Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Calling VB.NET DLL from C++

Posted on 2004-11-14
Medium Priority
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
  • 2
  • 2
LVL 16

Expert Comment

ID: 12582040
#import "CCCVblib.tlb" raw_interfaces_only named_guids no_namespace

Author Comment

ID: 12587136
No go...
It's got to be something basic.

Author Comment

ID: 12640824
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

ID: 12874969
This seems to me like a PAQ/refund.

Accepted Solution

modulo earned 0 total points
ID: 13140010
PAQed with points refunded (500)

Community Support Moderator

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

571 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