You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
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.
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.
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.
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).
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, 01:40 PM.
<b>George W. Bleck</b>
<img src='http://www.blecktech.com/myemail.gif'>
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.
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Comment