In C, I use GetProcAddress( ) to retrieve the function pointer in DLL. How
about in VB ?
Bests,
Filex Yeung
E-Mail Address : filex...@ctint.com
>In order to load a DLL in VB Application in runtime, I use LoadLibrary API
>and the DLL is loaded successfully. However, how can I use the functions
in
>DLL ?
>
You can't do it this way in VB. You have to write a Declare statement to use
functions in DLLs.
--
Ben Baird, MVP
Microsoft SiteBuilder Network Level 2
Visual Basic Thunder, v. 2.0
http://www.cyberhighway.com/~psy/
Common Controls Replacement Project, Official Member
http://www.mvps.org/ccrp/
Please direct your programming questions to the newsgroups.
If all you want to do is call a C function in a DLL make sure the function
is declared as WINAPI. (Also make sure the function is exported from the
DLL) Then use the DECLARE statement in visual basic to explain to the VB
program in which DLL the function resides and what the parameters are.
(All this is so that VB can help "SHIELD" you from the complexities of the
process - like it or not)
Esko
Filex Yeung <filex...@ctint.com> wrote in article
<358a3...@news01.imsbiz.com>...
The problem is , can I retrieve the function pointer in DLL by using
GetProcAddress( ) WINAPI ? Even I can retrieve the function pointer, How to
use such pointer ? How to call the function and pass arguments ?
Filex Yeung
E-Mail Address : filex...@ctint.com
>Esko wrote in message :
-Sebastian Odin Smith
>I haven't tried it yet, but a suggestion for using function pointer is
>VB is to setup a module level boolean, call CreateThread passing the
>address of the function, and monitor the boolean in the main thread.
>Have the spawned thread set the boolean just before terminating.
I would be interested in knowing how you call GetProcAddress from vb.
TIA,
Gerry T.
Hi Gerry:
'Code snippet starts:------------------------------------
Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal
lpLibFileName As String) As Long
Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long,
ByVal lpProcName As String) As Long
Declare Function FreeLibrary Lib "kernel32" (ByVal hModule As Long) As
Long
Public DLLModuleHandle as Long,DLLProcAddress as Long
DLLModuleHandle = LoadLibrary("c\windows\system\mydll.dll"+chr$(0))
DLLProcAddress = GetProcAddress(DLLModuleHandle, "MyFunction")
'code snippet ends--------------------------------------------
This assumes your DLL is "mydll.dll" and that the exported DLL function
is MyFunction.
At some point later in the code you'll have to do a FreeLibrary call or
your DLL will remain loaded (at least in the VB development environment
-- I haven't yet seen if that's true for EXEs).
It's true that you can't call the procedure address directly from VB5
using the returned DLLProcAddress -- I haven't tried the Thread method
so can't comment. I use the above code to pass the DLLProcAddress value
to a "call forwarding" DLL written in C, which in turn calls my main DLL
written in Assembly Language. I do this because I have never yet been
able to call a 32-bit ASM DLL (written using TASM 5.0) directly from
VB5, and this is my workaround patch.
If anyone *has* managed to call TASM DLLs from VB5, I'd love to hear how
they did it! I was never able to get VB5 to find the ASM DLL using the
standard Declare method. GetProcAddress works fine, however....
Regards,
Ian McLaren
--
Jeremy - my reply address is foiled
Ian McLaren wrote in message <35974C...@california.com>...