How do I use Visual Basic 2005 class libraries in C\C++ environments?
I currently attempting to get a Visual Basic 2005 Class library to import and function in a C++\C environment. Unfortunately my experience with COM and DLLs is very limited. I was able to Create a VB Class Library that compiled and ran against my visual Basic debugger. However when it came time to write a C++ debugger I had a very difficult time finding resources and in general I am pretty stuck. I had registered the Class library as a COM object so I created a .tlb file and tried using the #import method, this failed miserably. I see the namespace, and the class and the interface for the COM but I can't seem to get a valid instance of the object when I run my C++ app.
Here is A basic Picture of my VB Class library DLL
( There is a listener thread in one of the Classes)
'Imports
Imports System.Net
Imports System.text
Imports System.Threading
'My interface
Public Interface IAutoLink
Sub init(ByVal strSettings As String)
Sub Add(ByVal strData As String)
Function RetrieveOldest() As String
Function ArrayContents() As String
Sub StartListening()
Sub StopListening()
End Interface
'The Class itself
Public Class AutoLinkClass
Implements IAutoLink
Private Shared m_Packet As Packet
Private Shared m_Queue As CircleQ
Private UDPclient As UDPcommunications
Public Sub init(ByVal strSettings As String) Implements IAutoLink.init
Public Sub Add(ByVal strData As String) Implements IAutoLink.Add
Public Function RetrieveOldest() As String Implements IAutoLink.RetrieveOldest
Public Function ArrayContents() As String Implements IAutoLink.ArrayContents
Public Sub StartListening() Implements IAutoLink.StartListening
Public Sub StopListening() Implements IAutoLink.StopListening
Public Sub Terminate()
' A bunch of internal Classes
#Region "Internal Classes"
End Class
Heres the C++ code I have that doesn't work
#include <iostream>
#include <string>
#import <mscorlib.tlb> raw_interfaces_only
#import "AutoLink.tlb" no_namespace named_guids
using namespace std;
int main(int argc, char* argv[])
{
string hold;
try{
IAutoLink *test = NULL;
CoInitialize(NULL);
LPVOID *Test2 = NULL;
_bstr_t Value;
string addValue;
string::size_type length = 0;
bool bRunning = true;
HRESULT hr;
hr = CoCreateInstance(CLSID_AutoLinkClass,NULL,CLSCTX_INPROC_SERVER,
IID_IAutoLink, Test2);
if (FAILED(hr))
{//This basically always fires
MessageBox(NULL,"Couldn't create the instance!","VB Library",MB_OK);
}
test = (IAutoLink*) Test2;
test->init("8080,192,168,10,104");
while (bRunning)
{
cout << "Options:\nA:(string)=> to add a String to the queue\nP-to pop a string from the Queue\nq- To Quit\n?";
cin >> hold;
if ((hold.find("A",0) != string::npos) || (hold.find("a",0) != string::npos ))
{
//Do an add
length = hold.length();
length = length - 2;
addValue = hold.substr(2,length);
Value = "VALUE";
}
else if (hold == "q" || hold == "Q")
{
bRunning = false;
CoUninitialize();
test->Release();
}
}//While Loop
}
catch (_com_error &ComError)
{
cout <<"COM ERROR!!!!!\n any key to continue";
cin >> hold;
}
catch (...)
{
cout<< "Other Error\n any key to continue";
cin >> hold;
}
return 1;
}
I would greatly appreciate any advice or resources on this issue .
Thanks
Christopher J

