Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Geek Culture / Dynamic DLL Loading in Visual Basic

Author
Message
Rob K
Retired Moderator
22
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 8th Oct 2003 11:24
In order to load DLLs dynamically in Visual Basic (ie. where you can specify the DLL name & function at runtime), do you have to use LoadLibrary or does VB provide any inbuilt way. I wasn't able to find any helpful info on the web.

MushroomHead
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 8th Oct 2003 14:30 Edited at: 8th Oct 2003 14:31


Assuming "mymsgbox" command exists in "mymsgbox.dll". That example is not tested and me writing from memory.
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 8th Oct 2003 15:06 Edited at: 8th Oct 2003 15:09
I usually use functions instead, like declare the .dll as a function and pass the parameters that way, for example, this would load and declare Shell32.dll for use in loading file extensions with their set applications:

Private Declare Function ShellExecute Lib _
"shell32.dll" Alias "ShellExecuteA" _
(ByVal hWnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long


This would be at the very start of your code, then to call it I would use:

runin = ShellExecute(Me.hWnd, _
vbNullString, FILE, _
vbNullString, _
"", _
SW_SHOWNORMAL)


The runin variable would store the application ID.


Van-B

My cats breath smells of cat food.
Dave J
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Feb 2003
Location: Secret Military Pub, Down Under
Posted: 8th Oct 2003 16:28
I thought they had to be declaread globally within a module in which case it's not possible to do.


"Computers are useless they can only give you answers."
Rob K
Retired Moderator
22
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 8th Oct 2003 17:11
@Mushroom

Thanks, but I don't know the name of the DLL before I load the program though, it is found at runtime.

AM_
20
Years of Service
User Offline
Joined: 5th Oct 2003
Location:
Posted: 8th Oct 2003 17:19
Yeah I've done dynamic DLL loading in VB before. It's kinda tricky though. Look up the Windows API's LoadLibrary, GetProcAddress and CallWindowProc.
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 8th Oct 2003 17:42
yeah, it helps to know the dll beforehand and instantiate it as public or private object

-RUST-
kingius
21
Years of Service
User Offline
Joined: 16th Oct 2002
Location:
Posted: 8th Oct 2003 17:57
You can latebind COM objects very easily like this:

set objConnection = createObject("adodb.connection")

(use set if VB is pre-.Net)

Login to post a reply

Server time is: 2024-09-20 15:31:45
Your offset time is: 2024-09-20 15:31:45