Announcement

Collapse
No announcement yet.

Custom DLL handling

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

  • BOB MECHLER
    replied
    I think I'm getting the hang of it. To start I used a program from Steven Pringles3 called dllutil in Poffs that took 3 parameters, the original DECLARE, DLL NAME and path if needed and the output file. The code in the output file code I just put in the include file and remarked out the DECLARE statement. I couldn't call the function directly but indirectly. Here is the output:
    Code:
    'DECLARE FUNCTION GET_CHN_PRD LIB "LBCHNPRD.DLL" ALIAS "GET_CHN_PRD" (STRING) AS STRING
    ' DLL Declares - custom for CTRU
    ' =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    ' |v1.9x 10/04/07 DDB - BT22266 move from standard DLLDECL.INC
    ' =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    DECLARE FUNCTION GET_CHN_PRD(STRING) AS STRING
    TYPE DLLCTRUType
         pGET_CHN_PRD AS DWORD
    END TYPE
    
     GLOBAL DLLCTRUData AS DLLCTRUType
    FUNCTION DLLCTRUInitialize(BYVAL sLibrary AS STRING) AS LONG
     'Dim DLLCTRUData As DLLCTRUType
    
     LOCAL szLib  AS ASCIIZ * 128
     LOCAL hLib   AS DWORD
     szLib = sLibrary
     hLib = LoadLibrary(szLib)
     IF ISFALSE(hLib) THEN
        FUNCTION = 0
        EXIT FUNCTION
     END IF
    
     DLLCTRUData.pGET_CHN_PRD = GetProcAddress(hLib, "GET_CHN_PRD")
    
     FUNCTION = hLib
    
    END FUNCTION
    
    FUNCTION DLLCTRU_GET_CHN_PRD(F1_ACTNR AS STRING)  AS STRING
     LOCAL Result AS STRING
     IF DLLCTRUData.pGET_CHN_PRD THEN
        CALL DWORD DLLCTRUData.pGET_CHN_PRD USING GET_CHN_PRD(F1_ACTNR) TO Result
     END IF
     FUNCTION = Result
    END FUNCTION
    In the program all I had to do was the following:
    Code:
    Instead of:
    
            CHN_PRD$ = GET_CHN_PRD(BYCOPY F1.ACTNR$)
    
    I used this:
    
            CALL DLLCTRUInitialize("LBCHNPRD.DLL")
            CHN_PRD$ = DLLCTRU_GET_CHN_PRD(BYCOPY F1.ACTNR$)
    Looks like the code could be generalized even more, don't you think?

    George's code looks more generalized at first glance. I'll have to play with this method too.

    Bob Mechler

    Bob Mechler

    Leave a comment:


  • George Bleck
    replied
    Code:
     
     
    DECLARE FUNCTION FunctionTemplate_EntryInterface( myvariable list ) AS LONG
     
     
    FUNCTION InstantiateModule( strModulePath as string, my supplied variables ) AS LONG
     LOCAL hLibrary AS DWORD
     LOCAL pProc AS DWORD
     LOCAL lngresult AS LONG
     hLibrary = LOADLIBRARY( BYVAL STRPTR( strModulePath ))
     IF hLibrary THEN
      pProc = GETPROCADDRESS( hLibrary, "ENTRYINTERFACE" )
      IF pProc THEN CALL DWORD pProc USING FunctionTemplate_EntryInterface( my supplied variable) TO lngResult
      CALL FREELIBRARY( hLibrary )
     ELSE
     END IF
    END FUNCTION
    Here is something I am using to iterate through my "plugin" DLL's
    Last edited by George Bleck; 11 Oct 2007, 12:40 PM.

    Leave a comment:


  • Michael Mattias
    replied
    Originally posted by BOB MECHLER View Post
    Is it possible to call a DLL using LoadLibrary etc without Declaring the DLL?
    Not to be too picky about semantics here, but you don't DECLARE a "DLL."

    You do DECLARE procedures - SUBs and FUNCTIONs.

    If you use the "LIB" clause in your DECLARE statement for a procedure and that procedure is referenced in your program, then that library must be available to the program at runtime, or you get that "some component is missing" message and the application will not start.

    When using LoadLibrary/GetProcAddress/CALL DWORD, you don't use the LIB clause in your DECLARE statement for the procedure (assuming you use a DELCARE at all, but I always do so I can use the CALL DWORD ... USING syntax), so the library need not be available at load time and you can decide at runtime if the library is available or not. (or even, 'available but expired because it was a time-limited demo'... something else I do).

    MCM

    Leave a comment:


  • Simon Morgan
    replied
    Yes !

    Leave a comment:


  • BOB MECHLER
    replied
    Is it possible to call a DLL using LoadLibrary etc without Declaring the DLL?

    Leave a comment:


  • Michael Mattias
    replied
    What you describe is exactly the mechinism I use to supply priced options for both the Provider Payment Partner(tm) System and the EDI Pal ANSI ASC X12 Viewer-Editor-Printer software.

    If you license the option, you get an extra DLL (or two); the 'main' software looks for that DLL and only enables the extra feature if it's found.

    So yes, it's possible; but you do have to use LoadLibrary/GetProcAddress/CALL DWORD to call any of the optional functions.

    MCM

    Leave a comment:


  • BOB MECHLER
    replied
    Thanks Simon. I've got Poffs so I'll look there to. Just needed to know it was possible. Normally all the DLL's we use, every customer needs and has.

    Bob Mechler

    Leave a comment:


  • Simon Morgan
    replied
    Yes, but you need to use a more complicated calling procedure for the DLL function, involving LOADLIBRARY, GETPROCADDRESS and CALL DWORD. (Search this forum for those terms to get some example code).

    Otherwise, for the people without the DLL, the EXE will fail to load.

    Leave a comment:


  • BOB MECHLER
    started a topic Custom DLL handling

    Custom DLL handling

    Is it possible to declare a DLL that is custom for one customer and only referred to in our standard program when that customer is using it and not have to send the same custom DLL to every customer who uses the standard program but will never call this special function.

    Bob Mechler
Working...
X