We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

VB.NET project refrence C++ DLL

corduroy9
corduroy9 asked
on
Medium Priority
625 Views
Last Modified: 2008-02-01
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?
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Ignacio Soler GarciaSolution Architech & Technical Lead

Commented:
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!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.