Solved

Unload a DLL From VB

Posted on 1998-10-29
7
248 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
  • 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sending a email via excel using vba 6 80
How does CurrentUser work? 10 37
How to make an ADE file by code? 11 83
Set email body to html using vbscript 6 41
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

785 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