Visual Basic Dynamically Linked DLLs
-----------Wow, I need a life.--------------
How can Visual Basic Dynamically Link to a DLL?
I have the following code
Option Explicit
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Declare Function FreeLibrary Lib "kernel32" Alias "FreeLibrary" (ByVal hLibModule As Long) As Long
Private Declare Function GetProcAddress Lib "kernel32" Alias "GetProcAddress" (ByVal hModule As Long, ByVal lpProcName As String) As Long
Sub Form_Load()
Dim HDL as Long
Dim FuncHDL as Long
HDL = LoadModule("user32")
FuncHDL = GetProcAddress(HDL, "GetCursorPos") ' This is just to use as a sample func.
' What do I do Here?
' I tried Call (FuncHDL), but no success
FreeLibrary HDL
End Sub
Edited by - nes8bit on 2/10/00 3:44:15 PM
There is no need to call loadlibary or freelibrary explicitly with VB.
For instance, using your sample, to call GetCursorPos from VB you would need the following declarations:
Public Declare Function GetCursorPos Lib "user32" Alias "GetCursorPos" (lpPoint As POINTAPI) As Long
Public Type POINTAPI
x As Long
y As Long
End Type
Then, use it like:
Dim pt As POINTAPI
Dim rVal As Long
rVal = GetCursorPos(pt)
Debug.Print CStr(pt.x) & " " & CStr(pt.y)
HTH,
-mordell
__________________________________________
Yeah, sure... we are laughing WITH you ...
Yeah, sure... we are laughing WITH you ...
Visual Basic doesn''t support the concept of function pointers. One way to get around this is to create a DLL in C yourself and pass the function pointer and the arguments to a function in your new DLL. Messy? Yes. A better option in VB is not to use standard DLLs but to use COM objects.
I know all of that, but I wanted to make some portions of my engine open-source for people to play with. Everything that is in C++ will be in open source. I also wanted to make dynamic calls to dll''s for certian chipsets. To take advantage of say... AMD''s functions. Well anyhoo, my final approach was to call the functions in a seperate dll like SiCrane said. Thanks anyway.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement