Passing an address like this instead of DECLAREing an external is IMNSHO good technique.
Besides, you are probably already familiar with passing a code address from using the WinAPI "Enumxxxx" functions.
If you are really curious, here's a demo I created a long time ago on the same subject...
PB/WIN: Write your own ENUM functions to callback September 23, 2002
Announcement
Collapse
No announcement yet.
Calling an exe from a dll
Collapse
X
-
As long the exe loads your dll you can perfectly use ordinary declares.
Of course the name of the exe should be static (but no folder required)
I do this myself.
Leave a comment:
-
-
Nevermind. Figured it out:
EXE code:
Code:#COMPILE EXE "Parent.exe" DECLARE FUNCTION DLL_Receive_EXE_Function_Address LIB "CHILD_DLL.DLL" ALIAS "DLL_Receive_EXE_Function_Address" (BYVAL Address AS DWORD) AS LONG DECLARE FUNCTION DLL_Run LIB "CHILD_DLL.DLL" ALIAS "DLL_Run" AS LONG FUNCTION Send_Address_Of_EXE_Function (BYVAL Address AS DWORD) AS DWORD DLL_Receive_EXE_Function_Address Address END FUNCTION FUNCTION EXE_Function(BYVAL InputValue1 AS LONG) AS LONG TEXT$ = "EXE_Function has been called by the dll " + $CRLF+_ "The value " + FORMAT$(InputValue1,"# ") + "has been received." MSGBOX TEXT$,,"This is the EXE talking" END FUNCTION FUNCTION PBMAIN Send_Address_Of_EXE_Function CODEPTR(EXE_Function) DLL_Run END FUNCTION
DLL code
Code:#COMPILE DLL "Child_DLL" DECLARE FUNCTION EXE_Function(BYVAL InputValue1 AS LONG) AS LONG GLOBAL GLOBAL_EXE_Function_Address AS DWORD FUNCTION DLL_Receive_EXE_Function_Address ALIAS "DLL_Receive_EXE_Function_Address" (BYVAL Address AS DWORD) EXPORT AS LONG GLOBAL_EXE_Function_Address = Address TEXT$ = "Address received is " + FORMAT$(Address,"#") MSGBOX TEXT$,,"This is the DLL talking" END FUNCTION FUNCTION DLL_Run ALIAS "DLL_Run" EXPORT AS LONG LOCAL Value_To_Send_To_Exe AS LONG Value_To_Send_To_Exe = 4 TEXT$ = "DLL_Run has been called by the exe. Sending value " + FORMAT$(Value_To_Send_To_Exe,"# ") + "to EXE_Function" MSGBOX TEXT$,,"This is the DLL talking" CALL DWORD GLOBAL_EXE_Function_Address USING EXE_Function(Value_To_Send_To_Exe) END FUNCTION
Last edited by Todd Wasson; 27 Nov 2007, 04:47 PM.
Leave a comment:
-
-
Calling an exe from a dll
I found this on the subject:
User to user discussions about the PB/Win (formerly PB/DLL) product line. Discussion topics include PowerBASIC Forms, PowerGEN and PowerTree for Windows.
It's from 2001 though. Is this still the way to go about calling an exe function from a dll rather than the other way around? The exe functions will be in a C++ exe called by a PB DLL it's already using. Not sure if that would make things any different than a PB to PB thing, which I don't know how to do either. I assume CALL DWORD would be used in the dll after receiving the exe function's addresses from other calls at program initialization. This would work just peachy for our purposes. Anyone know of any other examples?
The exe function doesn't need to return a value to the dll if that simplifies things. It also does not need to be a separate thread or callback function. Just a simple F_Add_Value(BYVAL a AS SINGLE) AS LONG type of thing would suffice. Anyone know what I should be searching for or have a simple example handy?
ThanksLast edited by Todd Wasson; 27 Nov 2007, 04:12 PM.Tags: None
-
Leave a comment: