
COM client crashes calling COM method
You should not be using cast's when passing BSTR parameters....in fact , in
your sample code you are not passing BSTR's at all (but using casting to
shut up the compiler attempting to warn you about your error).
Your "in" and "out" parameter should not be array's of char but should be
allocated BSTR (using one of the BSTR smart types or using SysAllocString
explicitly).
You cannot pass a string literal and use a cast to fool the compiler into
thinking it is a BSTR.
Peter Partch
My Win32 console app can't return from a call to COM component. Debugging
through
the COM component yields a successful passing of parameters from the client,
but
attempting to return to the client yields a "User breakpoint called from
code at
0x77f9f9df". Attempting to run past this point repeats the same message over
and
over. Here's the client code:
CoInitialize(0);
// Other initializations.
{ // Extra scope level here, so smart pointers are released prior to
BLOWFISHCOM2Lib::ICryptoPtr pCrypto;
// the 'Ptr' suffix implies a smart-pointer wrapper.
if (SUCCEEDED(pCrypto.CreateInstance(CLSID_Crypto)))
{ // work with the object.
ICrypto *ptr = pCrypto.GetInterfacePtr();
char in[256], out[256];
memset(out,0,256);
strcpy(in, "This is a test...");
ptr->blowfish((BSTR) in, (BSTR) out, 1, (BSTR) "2343");
// never returns from above COM call
char tmp[256];
sprintf(tmp,"%s",out);
Quote:
}
// smart pointer automagically releases com object after this brace...
Quote:
}
CoUninitialize();