CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2008
    Posts
    3

    Question 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

  2. #2
    Join Date
    Dec 2003
    Location
    Northern Ireland
    Posts
    1,362

    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
    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook


    0100 1101 0110 1001 0110 0011 0110 1000 0110 0001 0110 0101 0110 1100 0010 0000 0100 0101 0110 1100 0110 1100 0110 0101 0111 0010

  3. #3
    Join Date
    Nov 2008
    Posts
    3

    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

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Need help, handling C++ dll in vb.net

    Sounds like you need to create a DELAGATE to handle the external condition
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Nov 2008
    Posts
    3

    Re: Need help, handling C++ dll in vb.net

    Quote Originally Posted by dglienna View Post
    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

  6. #6
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    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
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured