473,396 Members | 1,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Exception from HRESULT when using COM server and ISupportErrorInfo

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
1 6299
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Lekyan | last post by:
I have problem setting the password for an ADAM user using C#. I used the SetPassword code given in the Microsoft page, changed several parameters, but ran into an exception. I wonder if other...
4
by: Mark | last post by:
I have a COM object that calls into a C# Forms library. The library can throw exceptions and I want to handle the exceptions in COM. Adam Nathan wrote a Microsoft sponsored book titled .Net and Com...
4
by: Shimon Sim | last post by:
I just switch my asp application to .net 2 and got this error. Any reasons why? Thank you. Server Error in '/RAFEmployee' Application....
2
by: Richard Collette | last post by:
Hi, I have a service, that runs perfectly when executed outside of the web service environment. When called as a web service I get the exception listed below sporadically. A call to the web...
1
by: zoltix | last post by:
Hello, I have a problem with an IIS server on windows 2003 server. I developed a web application on Windows Xp with the standard classes Membershi(System.Web.Security.SqlMembershipProvider,...
11
by: Don | last post by:
When using Visual Basic .NET with a reference to Interop.Outlook, is there a way to get more detailed information about an error other than Exception.Message or Exception.ToString? For example,...
0
by: neo | last post by:
Hi to all I am nitin, my problem is that i am trying to automate word application using asp.net. I am using visual studio 2005 and added following dlls as references(Microsoft Word 11.0 Obejct...
1
by: tamasumalta | last post by:
I am using the attached code Private Sub StartApplicationProcess InitialiseObject() oWord.Visible = True oDoc = oWord.Documents.Open(StrStackPath) oWord.Visible = True end sub The...
4
by: yogarajan | last post by:
The specified module could not be found. (Exception from HRESULT: 0x8007007E) Description: An unhandled exception occurred during the execution of the current web request. Please review the stack...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.