Results 1 to 10 of 10

Thread: Data Persists in Dll

  1. #1

    Thread Starter
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383

    Resolved 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.

  2. #2
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    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]

  3. #3

    Thread Starter
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383
    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?

  4. #4
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    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]

  5. #5

    Thread Starter
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383
    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!

  6. #6
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Perhaps an API like KillProcess or something to that effect?
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  7. #7

    Thread Starter
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383
    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:
    1. ClearDll ("C:\ANAread\impintrp.dll")
    VB Code:
    1. Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
    2. Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
    3. 'Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
    4. '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
    5. Sub ClearDll(strPath As String)
    6.     On Error Resume Next
    7.     'KPD-Team 1999
    8.     'URL: [url]http://www.allapi.net/[/url]
    9.     'E-Mail: [email][email protected][/email]
    10.     'We're going to call an API-function, without declaring it!
    11.     Dim lb As Long, pa As Long
    12.     'map 'user32' into the address space of the calling process.
    13.     lb = LoadLibrary(strPath)
    14. '    'retrieve the address of 'SetWindowTextA'
    15. '    pa = GetProcAddress(lb, "SetWindowTextA")
    16. '    'Call the SetWindowTextA-function
    17. '    CallWindowProc pa, Me.hWnd, "Hello !", ByVal 0&, ByVal 0&
    18.     'unmap the library's address
    19.     FreeLibrary lb
    20. End Sub

  8. #8
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    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]

  9. #9

    Thread Starter
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383
    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:
    1. Private Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long
    2. Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
    3.  
    4. Sub ClearDll(strPath As String)
    5.     On Error Resume Next
    6.  
    7.     Dim hModule As Long
    8.     hModule = GetModuleHandle(strPath)
    9.     FreeLibrary hModule
    10.    
    11. End Sub

  10. #10

    Thread Starter
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383
    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
  •  



Click Here to Expand Forum to Full Width