Re: Can't compile VC++ program that call a VB DLL
jialge@online.microsoft.com ("Jialiang Ge [MSFT]") wrote:
Hello Tim,
Thank you for posting here. My name is Jialiang Ge[MSFT]. It's my pleasure
to work with you on this thread.
From you post, you were working with COM component, but I am still confused
about the structure of the project. I want to confirm the following things
with you.
1. Which one is your COM server, the VB dll or the VC++ project named
xxvbdll?
The VB dll
2. Where do you call CoCreateInstance? Did you create a new project as the
client to call the server? If yes, how do you reference IID__dgsAES,
CLSID_dgsAES and the _dgsAES interface from the client?
At the moment, I have a very small MFC 32-bit console app that's
trying to call this VB COM server DLL. The text (following AfxWinInit)
follows:
HRESULT hr;
_dgsAES *IVBdgsAES = NULL;
// Now we will intilize COM
hr = CoInitialize(0);
// Use the SUCCEEDED macro and see if we can get a pointer
// to the interface
if(SUCCEEDED(hr))
{
hr = CoCreateInstance( CLSID_dgsAES,
NULL,
CLSCTX_INPROC_SERVER,
IID__dgsAES,
(void**) &IVBdgsAES);
if(SUCCEEDED(hr))
{
COleVariant instr("input string");
VARIANT vinstr = instr.Detach();
BSTR outstr;
COleVariant salt("salt");
VARIANT vsalt = salt.Detach();
cout << "input str is : " << vinstr.bstrVal << endl;
// We can test this HR as well if we wanted to
hr = IVBdgsAES->strDecrypt(&instr, &vsalt, &outstr);
cout << "Output string is: " << CString(outstr) << endl;
// We can test this HR as well if we wanted to
hr = IVBdgsAES->Release();
}
else
{
// Something went wrong
cout << "CoCreateInstance Failed." << endl;
}
}
else
cout << "CoInitialize failed" << endl;
That's it. It includes the dgsCrypto.h file that was generated by
MIDL. dgsCrypto_i.cpp, also generated by MIDL. There's a dgsCrypt.lib
file which IU added to the project when the "Unresolved external"
messages appeared, but that didn't help/
In your code snippet, I notice that you are using the COM API like
CoCreateInstance, and benefiting from the type info: _dgsAES. Am I right
that you are using #import without smart pointers?
I don't know what a smart pointer is and I don't see "#import"
anywhere in here. I haven't used VC++ for a few years. I'm using VC++
6.0, which is not likely to change, given the funding situation around
here.
I'll look over your letter in detail.
--
Tim Slattery
MS MVP(Shell/User)
Slattery_T@bls.gov
http://members.cox.net/slatteryt