Announcement

Collapse
No announcement yet.

Help between PB DLL or CC??

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help between PB DLL or CC??

    We are interested in doing a web site with PowerBasic. Since
    there are two versions of PowerBasic CC or DLL, does anyone
    have a suggestion which one to use? Or which is better CGI
    or ISAPI?

    Also, sorry for my ignorance I know the DLL version can
    call another PB DLL, but can the CC call other CC compiled
    function?

    Thanks,
    Todd

  • #2
    PB/DLL can be used for ISAPI (PBDLL can create DLL's for in-process tasks). PB/DLL can also be used to create CGI apps, but you'll need to work through the API which requires the code to jump through a couple of hoops.

    PB/CC is best suited for CGI since it natively supports STDIN/STDOUT, etc, but does not create DLL's).

    Therefore the question is whether to do CGI or ISAPI. ISAPI usually offers better performance, but requires more work to write the code for. Also, since it is in-process, if the ISAPI code crashes for some reason, it may take the parent app (the web server) down with it (correct me if I'm wrong here guys?!).

    Anyway, before you make up your mind, try searching this BBS for "ISAPI" and also for "CGI" - you'll find examples of both approaches here and this may help you decide which approach will be easier for you.

    Yes, both EXE's and DLL's can call functions in other DLL's which can call functions in other DLL's which can call functions...ad infinitum (or you run out of memory! )

    PB/CC can also call functions in DLL's.

    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment


    • #3
      Lance, you're right on.
      Todd, i'd make a decision of which technology to use based on the number of hits your program will get. If it's a high traffic thing, then ISAPI is better. If it's lower traffic and the software will change often, you're better off with cgi exe's.
      I can tell you that most stuff I write currently can be compiled with either PBDLL as an ISAPI or PBCC as an EXE. This isn't too hard to do and is worth the extra effort. You can test with exe's because you don't have to reboot the web server in order to update them (like you do with isapi) and deploy live with ISAPI because they're faster.

      Below is the skeleton I use for a conditionally compiled web app.
      Note that I don't use any globals. Also, the WEB_SESSION_TYPE structures has a couple members remmed out. The pointer to the web variables (you'll have to substitute your own code to handle this) and the pointer to session variables. This could be an array or something.
      Bottom line is that if you can avoid globals by putting them in the structure instead of being global and then passing the structure to every call, you can compile as either isapi or cgi.
      --Don

      Code:
      '
      '  <filename>
      '
      '
      
      '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      '  Compiler Directives
      '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      #if %def(%pb_dll32)
         #compile dll 
         %COMPILE_ISAPI = 1
      #else
         #compile exe
         %COMPILE_CGI = 1
      #endif
      
      $PROGRAM_TITLE = "Program's Title"
      $PROGRAM_VERSION = "1.0"
      
      '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      '  Required generic libraries
      '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      #include "win32api.inc"
      #include "dd_isapi.inc"
      
      '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      '  Structures and constants
      '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      Type WEB_SESSION_TYPE
         db as Long                       'database handle
         'wd as WEB_DATA_TYPE             'structure of pointers to post/get/cookie data
         'pVar as LINKED_LIST_TYPE PTR    'pointer to variables list
         ECB as EXTENSION_CONTROL_BLOCK   'control block used by ISAPI interface
      End Type
      
      Global gCS as CRITICAL_SECTION
      
      '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      '  Function Prototypes
      '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      Declare Sub WriteOut(rSess as WEB_SESSION_TYPE, ByVal sMessage as String, _
            ByVal iEol as Long) 
      
      '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      '  Required program specific files
      '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      
      '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      '  EnterCritical
      '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      Sub EnterCritical()
         
         EnterCriticalSection gCS
         
      End Sub
      
      '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      '  LeaveCritical
      '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      Sub LeaveCritical()
         
         LeaveCriticalSection gCS
         
      End Sub
      
      '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      '  WriteOut
      '     Sends a line back to the server
      '     Either adding it the buffer or sending it directly back via StdOut
      '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      Sub WriteOut(rSess as WEB_SESSION_TYPE, ByVal sMessage as String, _
            ByVal iEol as Long) 
            
         #if %def(%COMPILE_ISAPI)
         if iEol then
            isapiWrite rSess.ecb, sMessage + $CRLF
         else
            isapiWrite rSess.ecb, sMessage
         end if
         
         #else
         if iEol then
            StdOut sMessage
         else
            Stdout sMessage;
         end if
         #endif
         
      End Sub
      
      #if %def(%COMPILE_ISAPI)
      '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      '  Lib Main
      '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      Function LibMain(BYVAL hInstance   AS LONG, _
                       BYVAL fwdReason   AS LONG, _
                       BYVAL lpvReserved AS LONG) EXPORT AS LONG
      
         Select Case fwdReason
         
            '- The DLL is loaded into memory
            Case %DLL_PROCESS_ATTACH      
               Function = 1
            
            '- The DLL is coming out of memory
            Case %DLL_PROCESS_DETACH         
               Function = 1
            
            '- The thread is coming into memory
            Case %DLL_THREAD_ATTACH
               LibMain = 1
            
            '- The thread is coming out of memory
            Case %DLL_THREAD_DETACH
               LibMain = 1 
         
         End Select
      
      End Function
      
      '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      '  GetExtensionVersion
      '     Initialization - called once when dll is loaded into memory
      '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      Function GetExtensionVersion Alias "GetExtensionVersion" _
                                   (pVer As HSE_VERSION_INFO) Export As Long
      
         pVer.dwExtensionVersion = MakLng( %HSE_VERSION_MINOR, %HSE_VERSION_MAJOR )
         pVer.lpszExtensionDesc = $PROGRAM_TITLE + " v" + $PROGRAM_VERSION
         InitializeCriticalSection gCS
         Function = 1
      
      End Function
      
      '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      '  TerminateExtension
      '     Termination - called once when the dll is unloaded
      '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      Function TerminateExtension Alias "TerminateExtension" (ByVal dwFlags As Dword) Export As Long
      
         DeleteCriticalSection gCS
         Function = 1
      
      End Function
      
      '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      '  HttpExtensionProc
      '     The isapi function. This is called when the dll is requested as
      '     an action in a web page.
      '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      Function HttpExtensionProc Alias "HttpExtensionProc" _
                                 (ECB As EXTENSION_CONTROL_BLOCK) Export As Long
            
                                    
      #else
      Function PBMain
      
      #endif
      
         Dim rSess as WEB_SESSION_TYPE
         
         '- Insert your own collection routines
         '  to grab isapi post/get/cookie variables 
         '  in both parts of the conditionally 
         '  compiled sections below.
         '
         #if %def(%COMPILE_ISAPI)
         rSess.ecb = ECB
         '- collect isapi variables
         #else
         InitializeCriticalSection gCS
         '- collect cgi variables
         #endif
         
      Main_done:
         '- Free variables or whatever 
         '  shutdown is necessary here.
         '
         #if %def(%COMPILE_CGI)
         DeleteCriticalSection gCS
         #endif   
      End Function

      ------------------
      dickinson.basicguru.com
      Don Dickinson
      www.greatwebdivide.com

      Comment


      • #4
        Oops, forgot two things ...
        1. the code above depends on the dd_isapi.inc file that can be downloaded from http://dickinson.basicguru.com on the code page.
        2. always use the WriteOut sub to send data back to the web browser - don't use stdout (because it's cgi specific).

        --Don

        ------------------
        dickinson.basicguru.com
        Don Dickinson
        www.greatwebdivide.com

        Comment


        • #5
          Tod,

          I can tell you that an isapi is great and less difficult than it seems. Yes, it can take the server down but that depends on how 'well' your code is written.
          Also, it takes a bit more trouble as mentioned but we wrote an app which is multi-user, both from a desktop approach and (using the isapi) a web approach.

          Also, isapi can provide you real control on cookies, server vars, logging, thread pooling, etc. It outperformes a VB COM by many times.

          I can really advice you to use ISAPI if you plan to use it on a larger scale later on. CGI will (depending on the 'heaviness' of your app) slow the server down.
          We are now working on included our own load balancing and providing our app as a plugin to a website. This independent service can than run a simple (more faster) webserver (like the freeware version written in PB) which even speeds things up even more (because we do not have to deal with IIS).

          Don's code is excellent to start with (worked for me!)

          Regards
          Jeroen

          ------------------

          Comment


          • #6
            Don,
            What web server software works with ISAPI?
            In particular does it work with Xitami?

            Thanks,
            Joe Murphy

            ------------------

            Comment

            Working...
            X