Results 1 to 7 of 7

Thread: Calling C++ from Visual Basic.Net

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    8

    Calling C++ from Visual Basic.Net

    Hi,

    Is it possible to call an MFC C++ DLL, either regular or DLL with MFC extension, from Visual Basic.Net ?

    Brgds

  2. #2
    Fanatic Member robbedaya's Avatar
    Join Date
    Jul 2002
    Location
    Belgium
    Posts
    872

    Re: Calling C++ from Visual Basic.Net

    the people at the .net forum should be able to help you better.

    http://www.vbforums.com/forumdisplay.php?f=25

  3. #3
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Calling C++ from Visual Basic.Net

    If you export a function from your DLL then you can call it by creating a blank function and using the <DllImport> attribute to import the C++ function.

    For example, Sleep()...
    VB Code:
    1. Imports System.Runtime.InteropServices
    2.  
    3. <DllImport("kernel32")> Private Shared Sub Sleep (ByVal dwMilliseconds As Integer)
    4. End Sub

    You could also use the Declare statement, but that has been deprecated in favour of DllImport which gives you more control. Declare is included in VB.NET for backwards compatibility.
    Last edited by penagate; Dec 15th, 2005 at 07:08 AM.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Calling C++ from Visual Basic.Net

    Moved to VB.NET

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    8

    Re: Calling C++ from Visual Basic.Net

    Quote Originally Posted by penagate
    If you export a function from your DLL then you can call it by creating a blank function and using the <DllImport> attribute to import the C++ function.

    For example, Sleep()...
    VB Code:
    1. Imports System.Runtime.InteropServices
    2.  
    3. <DllImport("kernel32")> Private Shared Sub Sleep (ByVal dwMilliseconds As Integer)
    4. End Sub

    You could also use the Declare statement, but that has been deprecated in favour of DllImport which gives you more control. Declare is included in VB.NET for backwards compatibility.
    If I test the DLL (FileXfer.dll) with a C++ program it works fine, but when I use a Visual Basic.Net application I received following error mgs :

    "An unhandled exception of type 'System.EntryPointNotFoundException' occurred in TestXferDLL.exe

    Additional information: Unable to find an entry point named XferFile in DLL FileXfer."

    I've made this declaration in the Visual Basic.net application:
    <DllImport("FileXfer")> Private Shared Sub XferFile()
    End Sub

    FileXfer.dll is in the windows\system32 folder so it should be available.

    Anybody knows why I receive this error ?

    Brgds

  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Calling C++ from Visual Basic.Net

    How did you export it? Is that the exact name you used?

  7. #7

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    8

    Re: Calling C++ from Visual Basic.Net

    Quote Originally Posted by penagate
    How did you export it? Is that the exact name you used?
    ------------

    I use _stdcall to export instead of _declspec(dllexport). Looks like its working now.

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