Solved

Unload a DLL From VB

Posted on 1998-10-29
7
249 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

820 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