|
-
Dec 15th, 2005, 05:06 AM
#1
Thread Starter
New Member
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
-
Dec 15th, 2005, 06:03 AM
#2
Fanatic Member
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
-
Dec 15th, 2005, 06:53 AM
#3
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:
Imports System.Runtime.InteropServices
<DllImport("kernel32")> Private Shared Sub Sleep (ByVal dwMilliseconds As Integer)
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.
-
Dec 15th, 2005, 07:06 AM
#4
Re: Calling C++ from Visual Basic.Net
-
Dec 16th, 2005, 04:11 AM
#5
Thread Starter
New Member
Re: Calling C++ from Visual Basic.Net
 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:
Imports System.Runtime.InteropServices
<DllImport("kernel32")> Private Shared Sub Sleep (ByVal dwMilliseconds As Integer)
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
-
Dec 16th, 2005, 08:27 AM
#6
Re: Calling C++ from Visual Basic.Net
How did you export it? Is that the exact name you used?
-
Dec 16th, 2005, 08:54 AM
#7
Thread Starter
New Member
Re: Calling C++ from Visual Basic.Net
 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|