VB.NET project refrence C++ DLL

When I try to reference a C++ DLL from a VB.NET Project I get this error message.  

"A reference to '..... dll' could not be added.  This is not a valid assembly or COM Component.  Only assemblies with extension 'dll' and COM components can be referenced.  Please make sure that the file is accessible, and that it is a valid assembly of COM component."

I know the dll works because it is currently working in a VB.60 Project.  Any Ideas yet?
LVL 2
corduroy9Asked:
Who is Participating?
 
Bob LearnedConnect With a Mentor Commented:
You have to use p/invoke or a Declare Function/Sub for non-COM DLL's:


p/invoke:

<System.Runtime.InteropServices.DllImport("user32.dll")> _
Private Shared Function LockWindowUpdate(ByVal hWndLock As IntPtr) As Int32
End Function

Declare:

Private Declare Function LockWindowUpdate Lib "user32" (ByVal handle As IntPtr) As Int32

Bob
0
 
Ignacio Soler GarciaSolution Architech & Technical LeadCommented:
What I use to do in that situations is to create a VB6 DLL Wrapper to be used into VB.NET. That makes life much more simple.

At VB6 create a project that access the functions you need in the C++ DLL. The VB6 functions have to be dessigned with byref parameters and always with simple types (Int, String, etc). Then your VB.NET app talks only with the VB6 DLL without any trouble related to unmanaged code and so on ...

I've used this approach on several projects with success.

Hope it helps!
0
All Courses

From novice to tech pro — start learning today.