Hello,
I wrote some functions und put them in a DLL. Now I want to call one exportet function from MS-Excel (VBA). The function runs fine, but after ending the function, the DLL do not terminate. The programicon remains in the taskbar and if I call the function again from Excel, some internal counters, which normally are unset and zero, start from the last positions.
It seems, the ddl remains internally in memory.
If I call the DLL from another PB-Program, all works correctly.
Here some code.
In the dll:
In the calling PB-program:
In the Excel VBA-program:
Can someone help me?
excuse my bad english!
I wrote some functions und put them in a DLL. Now I want to call one exportet function from MS-Excel (VBA). The function runs fine, but after ending the function, the DLL do not terminate. The programicon remains in the taskbar and if I call the function again from Excel, some internal counters, which normally are unset and zero, start from the last positions.
It seems, the ddl remains internally in memory.
If I call the DLL from another PB-Program, all works correctly.
Here some code.
In the dll:
Code:
FUNCTION LIBMAIN (BYVAL hInstance AS LONG, _ BYVAL fwdReason AS LONG, _ BYVAL lpvReserved AS LONG) AS LONG SELECT CASE fwdReason CASE %DLL_PROCESS_ATTACH FUNCTION = 1 CASE %DLL_PROCESS_DETACH FUNCTION = 1 CASE %DLL_THREAD_ATTACH FUNCTION = 1 CASE %DLL_THREAD_DETACH FUNCTION = 1 END SELECT END FUNCTION FUNCTION Hauptprogramm ALIAS "Hauptprogramm" (Options AS STRING) EXPORT AS LONG ...... code goes here
In the calling PB-program:
Code:
#COMPILE EXE #INCLUDE "C:\PBWIN80\WINAPI\WIN32API.INC" FUNCTION PBMAIN () AS LONG DIM Parm AS STRING DIM hLib AS LONG DIM pAddr AS DWORD Parm = COMMAND$ hLib = LoadLibrary( "PIV_Create.dll") pAddr=GetProcAddress(BYVAL hLib, "Hauptprogramm") CALL DWORD pAddr BDECL (Parm) freeLibrary hLib END FUNCTION another version with "DECLARE Program in DLL" like the VBA-example works also.
Code:
Declare Function Hauptprogramm Lib "C:\PIV_ADD\PIV_Create.DLL" (Options As String) As Long Sub PiVTest() Call Hauptprogramm("MyParameter") End Sub
excuse my bad english!
Comment