Solved

Unload a DLL From VB

Posted on 1998-10-29
7
242 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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 process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

708 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

17 Experts available now in Live!

Get 1:1 Help Now