By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,885 Members | 1,469 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,885 IT Pros & Developers. It's quick & easy.

Exception from HRESULT when using COM server and ISupportErrorInfo

P: n/a
Hi,

we have a (unmanaged) ATL COM server, which implements two interface:
ITestInterface1 and ITestInterface2. Both of these interfaces also support
the ISupportErrorInfo-interface.

Interface implementation is divided into two class: CTestInterface2, which
implements the ITestInterfac2, and CTestInterface1, which implements
ITestInterface1 AND ITestInterface2.

ITestInterface1 has only 1 method which is implemented like this:

// IDS_TESTSTRING_1 is defined in stringtable and it says "Error in
ShowLong"
// Methodname: : ShowLong
HRESULT hRes = Error( IDS_TESTSTRING_1 );
return hRes;

ITestInterface2 has also only 1 method and it is implemented like this:

// IDS_TESTSTRING_2 is defined in stringtable and it says "Error in
ShowChar"
// Methodname : ShowChar
HRESULT hRes = Error( IDS_TESTSTRING_2 );;
return hRes;
Now, when i code, in VB 6, something like this

Dim my1 As ATLSERVERLib.TestInterface1
Dim my2 As ATLSERVERLib.TestInterface2
' . . .
Set my1 = New ATLSERVERLib.TestInterface1
Set my2 = my1
my2.ShowChar

i get a nice exception which says "Error in ShowChar".

But when i do the same in C#

private ATLSERVERLib.TestInterface1 my1;
private ATLSERVERLib.TestInterface2 my2;
// . . .
my1 = new ATLSERVERLib.TestInterface1();
my2 = (ATLSERVERLib.TestInterface2)ti1;
my2.ShowChar();

i get a exception which says: "Exception from HRESULT: 0x80041172."

Any ideas? If you like, i can post the sourcecode for all of these projects.
thx

Kimmo Laine


Nov 15 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi Kimmo,

What exatcly does the Error() function do in the ATL COM? I remember from my
ATL experience that raising errors properly from a COM component is rather
tricky.

Here's the code I used in one of my ATL COMs:

CComError::CComError(HRESULT hr, const IID& iidInterface, UINT
unStringTableID):
_com_error(hr)
{
HRESULT hrInternal;
CComBSTR bstrErrorMsg;

bstrErrorMsg.LoadString(unStringTableID);

CComPtr<ICreateErrorInfo> pICEI;
if (hrInternal = SUCCEEDED(CreateErrorInfo(&pICEI)))
{
CComPtr<IErrorInfo> pErrorInfo;
pICEI->SetGUID(iidInterface);
pICEI->SetDescription(_bstr_t(bstrErrorMsg));
if (SUCCEEDED(hrInternal = pICEI->QueryInterface(IID_IErrorInfo,
(void**)&pErrorInfo)))
{
this->_com_error::~_com_error();
this->_com_error::_com_error(hr, pErrorInfo, true);
}
else
{
throw _com_error(hrInternal);
}
}
else
{
throw _com_error(hrInternal);
}
}

P.S. Let's move our discussion to the
microsoft.public.dotnet.framework.interop newsgroup not to irritate the
subscribers with scary ATL C++ code and COM Interop details.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Kimmo Laine" <reply.to@newsgroup> wrote in message
news:eV**************@TK2MSFTNGP11.phx.gbl...
Hi,

we have a (unmanaged) ATL COM server, which implements two interface:
ITestInterface1 and ITestInterface2. Both of these interfaces also support
the ISupportErrorInfo-interface.

Interface implementation is divided into two class: CTestInterface2, which
implements the ITestInterfac2, and CTestInterface1, which implements
ITestInterface1 AND ITestInterface2.

ITestInterface1 has only 1 method which is implemented like this:

// IDS_TESTSTRING_1 is defined in stringtable and it says "Error in
ShowLong"
// Methodname: : ShowLong
HRESULT hRes = Error( IDS_TESTSTRING_1 );
return hRes;

ITestInterface2 has also only 1 method and it is implemented like this:

// IDS_TESTSTRING_2 is defined in stringtable and it says "Error in
ShowChar"
// Methodname : ShowChar
HRESULT hRes = Error( IDS_TESTSTRING_2 );;
return hRes;
Now, when i code, in VB 6, something like this

Dim my1 As ATLSERVERLib.TestInterface1
Dim my2 As ATLSERVERLib.TestInterface2
' . . .
Set my1 = New ATLSERVERLib.TestInterface1
Set my2 = my1
my2.ShowChar

i get a nice exception which says "Error in ShowChar".

But when i do the same in C#

private ATLSERVERLib.TestInterface1 my1;
private ATLSERVERLib.TestInterface2 my2;
// . . .
my1 = new ATLSERVERLib.TestInterface1();
my2 = (ATLSERVERLib.TestInterface2)ti1;
my2.ShowChar();

i get a exception which says: "Exception from HRESULT: 0x80041172."

Any ideas? If you like, i can post the sourcecode for all of these projects.

thx

Kimmo Laine



Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.