COM Exceptions in C#
Posted
by Yaron Naveh
on Stack Overflow
See other posts from Stack Overflow
or by Yaron Naveh
Published on 2009-05-24T16:12:15Z
Indexed on
2010/04/25
5:43 UTC
Read the original article
Hit count: 472
I am consuming a cpp COM object from c# code. My c# code looks like this:
try
{
var res = myComServer.GetSomething();
}
catch (Exception e) { }
However the exception never contains any of the details I set in cpp, in particular my error message.
In my cpp side I have followed several examples I have found on the web:
...
ICreateErrorInfo *pcerrinfo;
IErrorInfo *perrinfo;
HRESULT hr;
hr = CreateErrorInfo(&pcerrinfo);
pcerrinfo->SetDescription(L"C++ Exception");
hr = pcerrinfo->QueryInterface(IID_IErrorInfo, (LPVOID FAR*) &perrinfo);
if (SUCCEEDED(hr))
{
SetErrorInfo(0, perrinfo);
perrinfo->Release();
}
pcerrinfo->Release();
return E_FAIL; // E_FAIL or other appropriate failure code
...
Am I missing anything? Is there anything else that could affect this, like marshaling, the interop creation or attributes of the com server itself?
© Stack Overflow or respective owner