Solved

Unload a DLL From VB

Posted on 1998-10-29
7
250 Views
Last Modified: 2010-04-30
Does anyone know how to unload a DLL from within a VB4.0 16 app? I have a conflict with ole2thk.dll when I open an Access datatbase. I can manually unload the dll just before the db open and everything works fine. I'm thinking of adding a winapi call to unload the dll just prior to the db open. I need the name and info on the winapi function, if such an function exists. Or does anyone know a better solution?

Thanks
0
Comment
Question by:joe_s
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 3

Expert Comment

by:vmano
ID: 1442407
try this:
Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long

-- lpModuleName is the DLL name. this will return the handle to the DLL, which is the hLibModule parameter in the next function

Declare Function FreeLibrary Lib "kernel32" Alias "FreeLibrary" (ByVal hLibModule As Long) As Long

-- hLibModule is the returned value from the GetModuleHandle API

let me know if this helps,
vmano
0
 

Author Comment

by:joe_s
ID: 1442408
Maybe I'm doing it wrong, I had tried those functions and I only get a '0' returned for the handle.
This is my code:

Dim hWnd As Long
Dim lRC As Long
Dim sModuleName As String

sModuleName = "c:\winnt\system\msajt200.dll"
hWnd = GetModuleHandle(sModuleName)
' At this point hWnd is equal to 0 no matter how I refer to
' the dll in sModuleName ("msajt200", "msajt200.dll",...)

lRC = FreeLibrary(hWnd)

Thanks though,
Joe
0
 
LVL 3

Expert Comment

by:fguerreiro_inix
ID: 1442409
Probably you got 0 for the handle because dll isn't running.

0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

Author Comment

by:joe_s
ID: 1442410
To vmano:

Your suggestion did help, just not on my NT WS which is probably another issue. I tried a loadlibrary and several freelibrary commands in VB4 on a 3.1 machine which is where the problem was and they worked fine.

Since the freelibrary function is what I was looking for resubmit something as an answer so I can give you the points. ( I have coded API's in VB5 on my NT WS before but these still return 0 instead of the handle. You'll really earn the points if you can answer that.)

Thanks,
Joe
0
 
LVL 3

Expert Comment

by:vmano
ID: 1442411
The only thing i can think of is: try loading your DLL with LoadLibrary API.
Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long

Then try the other two API functions, which i gave you ealier.

let me know if this helps
vmano
0
 

Author Comment

by:joe_s
ID: 1442412
vmano:

The loadlibrary / freelibrary did work. You keep sending comments so I can't give you the points. If you send it as an answer I can give you the points.

Thanks
0
 
LVL 3

Accepted Solution

by:
vmano earned 250 total points
ID: 1442413
here is the answer (all functions on 32 bit):
Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long

Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long
-- lpModuleName is the DLL name. this will return the handle to the DLL, which is the hLibModule parameter in the next function

Declare Function FreeLibrary Lib "kernel32" Alias "FreeLibrary" (ByVal hLibModule As Long) As Long
-- hLibModule is the returned value from the GetModuleHandle API

I think I did answer all your questions. Now, I am really waiting for earning the points.... :-) :-)
vmano

0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question