Call VB DLLs from C++
-
Why is it that C++ cannot utilize a DLL authored in Visual Basic? Is there somebody out there who is mixed language savvy enough to address this issue in an article? I'd be very interested in interfacing between the two or learning how VB / C++ can exchange delimited strings via Winsock / CSocket. Any ideas?
-
Why is it that C++ cannot utilize a DLL authored in Visual Basic? Is there somebody out there who is mixed language savvy enough to address this issue in an article? I'd be very interested in interfacing between the two or learning how VB / C++ can exchange delimited strings via Winsock / CSocket. Any ideas?
I do this all the time. #import "c:\path\to\my\vb.dll" rename_namespace("WHATEVER") Then simply use
WHATEVER::MyObjectPtr pObj = NULL;
try
{
HRESULT hr = pObj.CreateInstance( __uuidof(WHATEVER::MyObject) );
if (FAILED(hr))
{
_com_issue_error(hr);
}pObj->DoStuff();
}
catch (_com_error& e)
{
// please don't forget this part
}You still want an article? :confused:
-
I do this all the time. #import "c:\path\to\my\vb.dll" rename_namespace("WHATEVER") Then simply use
WHATEVER::MyObjectPtr pObj = NULL;
try
{
HRESULT hr = pObj.CreateInstance( __uuidof(WHATEVER::MyObject) );
if (FAILED(hr))
{
_com_issue_error(hr);
}pObj->DoStuff();
}
catch (_com_error& e)
{
// please don't forget this part
}You still want an article? :confused:
Cool! #import looks like a powerful directive, but how can it allow me to reference the VB DLL's method? Specifically, my VB DLL has one string function, "Execute", which accepts a string as an argument. So I'm not surprised to see the compiler complain that MyObjectPtr is not a member of WHATEVER. But when I replace "MyObjectPtr" with "Execute" I still get the same complaint. I really appreciate your help Tom. Thanks in advance for any insight you might wish to share. Haha! Yeah, maybe a short article. You can bet I'm going to create a few notes of my own if I ever get this approach to work.
-
Cool! #import looks like a powerful directive, but how can it allow me to reference the VB DLL's method? Specifically, my VB DLL has one string function, "Execute", which accepts a string as an argument. So I'm not surprised to see the compiler complain that MyObjectPtr is not a member of WHATEVER. But when I replace "MyObjectPtr" with "Execute" I still get the same complaint. I really appreciate your help Tom. Thanks in advance for any insight you might wish to share. Haha! Yeah, maybe a short article. You can bet I'm going to create a few notes of my own if I ever get this approach to work.
Short answer... You can use BSTR, CComBSTR, or _bstr_t datatypes to transmit strings over COM. I like _bstr_t the best because you can easily use any string and cast it to a _bstr_t without worrying about memory allocation. Confused? Don't be. A little bit of reading should clear up your questions. The long answer... I will put this in an article. I don't know when I'll get it done. But I'll shoot for this weekend.
-
I do this all the time. #import "c:\path\to\my\vb.dll" rename_namespace("WHATEVER") Then simply use
WHATEVER::MyObjectPtr pObj = NULL;
try
{
HRESULT hr = pObj.CreateInstance( __uuidof(WHATEVER::MyObject) );
if (FAILED(hr))
{
_com_issue_error(hr);
}pObj->DoStuff();
}
catch (_com_error& e)
{
// please don't forget this part
}You still want an article? :confused:
I have made better progress, but I seem to be up against a wall with this particular error: warning C4042: '_IID' : has bad storage class It doesn't seem to make any difference what type I define in VB to pass/return to/from the DLL. Byte, Integer, String, Variant -- all yield the same error.
-
Why is it that C++ cannot utilize a DLL authored in Visual Basic? Is there somebody out there who is mixed language savvy enough to address this issue in an article? I'd be very interested in interfacing between the two or learning how VB / C++ can exchange delimited strings via Winsock / CSocket. Any ideas?
hello karl well the VB's DLL is a ActiveX DLL which supports the COM so the functions exported by the VB's DLL can be called through the VB program. But You can call Funtion from DLL of C++ through VB so do not worry abt calling the VB's DLL through C++ and remove it from your mind i m student of M. Sc. Computer Science from india and expert in Message Digest Security