Need help, handling C++ dll in vb.net
Hi everyone,
I'm using visual studio 2005 and i'm using a third party C++ dll which cannot be directly added as reference in my project.... A sample project made in C++ has been provided together with the SDK, however the project i'm doing needs to be in vb.net.
In the dll i'm using there is a method called BioDRV_Enroll which is declared as DWORD BioDRV_Enroll(hWnd, lpReserved)
HWND hWnd <---- Window handle to receive the completion message.
LPVOID lpReserved <----Reserved(null must be set)
This method should return a message know as BIODRV_COMPLETE_ENROLL
and together with that is a WPARAM and LPARAM...
my problem is how to declare it in VB or VB.net for that matter and access those return message after i invoke the function..
Any help would be greatly appreciated as i am new to this programming language..
Thanks and Regards,
ByVal
Re: Need help, handling C++ dll in vb.net
Hello ByVal,
Welcome to codeguru :)
This is how I declare the PostMessage function in user32.dll:
Code:
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Public Function PostMessage( _
ByVal hWnd As IntPtr, _
ByVal Msg As UInteger, _
ByVal wParam As IntPtr, _
ByVal lParam As IntPtr) As Boolean
End Function
Hope it helps
Re: Need help, handling C++ dll in vb.net
Hi HairyMonkeyMay,
Thanks for the quick response.
Currently this is how i declare the method
Code:
Private Declare Function BioDRV_Enroll Lib "FvidDrv.dll" (ByVal HWND As Long, ByVal LPVOID As IntPtr) As Short
and i have a method that uses the function that looks like this
Code:
Private Function Enroll() As Boolean
Dim s As Long = BioDRV_Enroll(Me.Handle.ToInt32, Nothing)
If s <> 0
Return False
End If
Return True
End Function
It properly returns the correct value...as for this function a zero which signifies a normal exit...
however this is an asynchronous-type function and its completion is judged by the completion message called BIODRV_COMPLET_ENROLL.
The message reports the completion of the function above and it also has a WPARAM and LPARAM that accompanies the message...
my problem is on how to manipulate this WPARAM and LPARAM as i need to control them to get the returned handle to proceed with other processes.
Thanks in advance for your help...and i certainly thank you for the code snippet you gave, looks like that's how a true .net declaration is done.
Thanks and Regards,
ByVal
Re: Need help, handling C++ dll in vb.net
Sounds like you need to create a DELAGATE to handle the external condition
Re: Need help, handling C++ dll in vb.net
Quote:
Originally Posted by
dglienna
Sounds like you need to create a DELAGATE to handle the external condition
Hi dglienna,
You mentioned delegate, would it allow me to control an unmanaged dll directly in my vb.net project? my fear is that I would have to create another dll to handle all messages that is returned by the current dll, which is additional hassle.....if it is possible to handle this wparam and lparam using delegate in vb.net how can i go about with this? thank you very much for your time.
Thanks and Regards,
ByVal
Re: Need help, handling C++ dll in vb.net
I'm not sure, but you can take a look at this (and other) code:
http://www.codeproject.com/KB/vb/Delegate.aspx