|
-
Nov 22nd, 2004, 04:34 AM
#1
Thread Starter
Frenzied Member
Data Persists in Dll
I am currently passing data to a dll and recording the output.
If I send one set of data I get the correct information back.
If I restart the application and send a second set of data I get the correct information too.
However, if I write a loop that calls the dll, the first set of data gives the correct info, but the second set is wrong.
This implies to me that an array or something is not getting cleared in the dll before the second call.
Unfortunately, I didn't write the dll so I cant change it.
Is there any way of resetting the dll (removing it from memory?) before I make the second call?
I tried this http://www.vbforums.com/showthread.p...+memory+unload but it didn't help.
Last edited by agmorgan; Nov 22nd, 2004 at 01:08 PM.
-
Nov 22nd, 2004, 06:16 AM
#2
Retired VBF Adm1nistrator
You could check if an instance of the DLL is staying in memory or something. Is this a normal DLL or an ActiveX DLL?
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Nov 22nd, 2004, 06:26 AM
#3
Thread Starter
Frenzied Member
Its a Fortran Dll
How do I check if an instance of the DLL is staying in memory?
Will it be in the task manager?
-
Nov 22nd, 2004, 06:29 AM
#4
Retired VBF Adm1nistrator
Well it is has somehow been instantiated, it might be listed in Processes in Task Manager..... You could also try Process Explorer (www.sysinternals.com) and that will show you too if its staying in memory.
Also perhaps this is by design? Perhaps you're supposed to pass Nulls or some particular values to clear it?
That also might be a way to clear it. Pass in invalid data and it just might clear out the previous values?
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Nov 22nd, 2004, 07:04 AM
#5
Thread Starter
Frenzied Member
Thanks, that is a pretty neat app.
It confirms that the dll is staying in memory.
Just got to work out what to do about it now!
-
Nov 22nd, 2004, 07:17 AM
#6
Retired VBF Adm1nistrator
Perhaps an API like KillProcess or something to that effect?
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Nov 22nd, 2004, 08:14 AM
#7
Thread Starter
Frenzied Member
I had a look at AllAPI and FreeLibrary seemed to fit the bill, but it doesn't work.
Am I using it wrongly?
VB Code:
ClearDll ("C:\ANAread\impintrp.dll")
VB Code:
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
'Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
'Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Any, ByVal wParam As Any, ByVal lParam As Any) As Long
Sub ClearDll(strPath As String)
On Error Resume Next
'KPD-Team 1999
'URL: [url]http://www.allapi.net/[/url]
'We're going to call an API-function, without declaring it!
Dim lb As Long, pa As Long
'map 'user32' into the address space of the calling process.
lb = LoadLibrary(strPath)
' 'retrieve the address of 'SetWindowTextA'
' pa = GetProcAddress(lb, "SetWindowTextA")
' 'Call the SetWindowTextA-function
' CallWindowProc pa, Me.hWnd, "Hello !", ByVal 0&, ByVal 0&
'unmap the library's address
FreeLibrary lb
End Sub
-
Nov 22nd, 2004, 08:18 AM
#8
Retired VBF Adm1nistrator
Well if you could find the handle to the DLL in question you could possinly use FreeLibrary.
Try this...
Start afresh, e.g. reboot machine first.
Pass some test data to the DLL
Use Process Explorer to find the handle to the DLL if possible
Try passing that handle to FreeLibrary
Pass different data to the DLL
Does it provide the same result?
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Nov 22nd, 2004, 10:31 AM
#9
Thread Starter
Frenzied Member
I couldn't work out how to find the handle with Process Explorer
It lists the dll as in use, but not the handle.
The GetModuleHandle in combination with FreeLibrary removes the dll from memory
Unfortunately it crashes the program too!
VB Code:
Private Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
Sub ClearDll(strPath As String)
On Error Resume Next
Dim hModule As Long
hModule = GetModuleHandle(strPath)
FreeLibrary hModule
End Sub
-
Nov 22nd, 2004, 01:08 PM
#10
Thread Starter
Frenzied Member
Success!
It all dependend on where I put the calls!
Turns out I cant have it as a function.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|