Solved

Unload a DLL From VB

Posted on 1998-10-29
7
243 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to open Waze.com/livemap from address saved in DB? 26 178
MsgBox 4 48
fso.FolderExists("\\server\HiddenFolder$") 4 52
IF ELSE Statement in Excel Macro VBA 16 35
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

867 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now