VB.NET project refrence C++ DLL

Posted on 2006-03-21
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?
Question by:corduroy9
    LVL 96

    Accepted Solution

    You have to use p/invoke or a Declare Function/Sub for non-COM DLL's:


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


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

    LVL 5

    Expert Comment

    by:Ignacio Soler Garcia
    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!

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now