Calling VB.NET DLL from C++

Posted on 2004-11-14
Last Modified: 2010-04-01
Can anyone tell me how to call a VB.NET DLL from C++.
The VB.NET DLL is registered for COM Interop.
This is simply test code...  Simplify if necessary...

=========> The VB.NET DLL code is :

Imports System
Imports System.Runtime.InteropServices

Namespace CCCVblib

  <Guid("89439AD1-756F-4f9c-BFB4-18236F63251E"), _
  InterfaceType(ComInterfaceType.InterfaceIsIDispatch)> _
 Public Interface _CCCVblib
    <DispId(1)> Function GetMonth() As Integer
  End Interface

  <Guid("1376DE24-CC2D-46cb-8BF0-887A9CAF3014"), _
   ClassInterface(ClassInterfaceType.None), _
   ProgId("CCCVblib.VBClass")> Public Class VBClass
    Implements _CCCVblib

    Public CCCVblib()

    Public Function GetMonth() As Integer Implements _CCCVblib.GetMonth
      GetMonth = DateTime.Now.Month
    End Function

  End Class

End Namespace

=========>The C++ Calling code is :

#import "CCCVblib.tlb"
using namespace CCCVblib;

int cpptest(void)
int res;
HRESULT hresult;
CLSID clsid;

CoInitialize(NULL);      //initialize COM library
hresult=CLSIDFromProgID(OLESTR("CCCVblib.VBClass"), &clsid);    //retrieve CLSID of component
VBClass* t=NULL;
hresult=CoCreateInstance(clsid,NULL,CLSCTX_INPROC_SERVER,__uuidof(VBClass),(LPVOID *) &t);
   return true;
res = t->GetMonth ();  //call method  <-------------- Error 'Use of undefined type CCCVblib::VBClass
t->Release();   //call method    <--------------  Error 'Use of undefined type CCCVblib::VBClass
CoUninitialize();  //Unintialize the COM library
return false;

The C++ does not find a function in Class VBClass.  What am doing wrong.
Question by:PSernz
    LVL 16

    Expert Comment

    #import "CCCVblib.tlb" raw_interfaces_only named_guids no_namespace

    Author Comment

    No go...
    It's got to be something basic.

    Author Comment

    Found the problem myself..

    The C++ function was referencing the VB DLL by the Class rather than by the assembly.
    Rather than VBClass simply use the reference _CCCVblib.
    LVL 16

    Expert Comment

    This seems to me like a PAQ/refund.

    Accepted Solution

    PAQed with points refunded (500)

    Community Support Moderator

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
    Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
    The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
    The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

    737 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

    19 Experts available now in Live!

    Get 1:1 Help Now