How to raise COM exception with support_error_info attribute ?

  • Thread starter Thread starter Onega
  • Start date Start date
O

Onega

Hi

I have problem raising COM exception with
support_error_info("IMyinterface").
It is an ATL wizard generated COM Exe project(VC++2003)

My interface looks like:
[
object,
uuid("2FAE9160-300F-43F6-A90F-668A2A2EB7F0"),
dual, helpstring("IMyinterface Interface"),
pointer_default(unique)
]
__interface IMyinterface: IDispatch
{
[id(1), helpstring("method Test")] HRESULT Test([in] BSTR bsTestValue);
};

[
coclass,
threading("apartment"),
support_error_info("IMyinterface "),
event_source("com"),
vi_progid("Somthing.Something"),
progid("Somthing.Something.1"),
version(1.0),
uuid("D9DB6B19-6D07-4EEB-91A0-196059D5486E"),
helpstring("SomethingClass")
]
class ATL_NO_VTABLE Something:
public IMyinterface
{

STDMETHODIMP Test(BSTR bsTestValue)
{
if(true)
{
////////////////////I want to raise a COM exception here, how to do it?
/*The following code snippet works in non-attributed In-Proc COM project,
but under this situation it doesn't work as expected. I call my COM Server
via VBscript, the script engine only reports there is an unspecified error,
but not given detailed error message.
*/

IID IID_IMyinterface=__uuidof(IMyinterface);
ICreateErrorInfo *pcei = 0;
HRESULT hr = CreateErrorInfo(&pcei);
hr = pcei->SetGUID(IID_IMyinterface);
....
}

return S_OK;
}

}

Your suggestion is welcome. Thanks a lot.
In an online sample chapter of the book
COM Programming with Microsoft? .NET
Author Julian Templeman, John Paul Mueller

I found there is a chapter dealing with exception handling and attributed
programing. But I don't have this book on-hand. And the book is not
available locally.

Onega
 
Onega said:
Hi

I have problem raising COM exception with
support_error_info("IMyinterface"). ....
public IMyinterface
{

STDMETHODIMP Test(BSTR bsTestValue)
{
if(true)
{

Use ATL for rise error
Error("Your error message" , __uuidof(IMyinterface));

in client u could get your text error by this

CComQIPtr<ISupportErrorInfo> pISERPtr (pInterface);
//pInterface->QueryInterface(IID_ISupportErrorInfo, (void**)&pISER);
// Does this interface have COM exception support?
if(SUCCEEDED(pISERPtr->InterfaceSupportsErrorInfo(riid)))
{
if(SUCCEEDED(GetErrorInfo(NULL, &pEI)))
{
ITypeLib* pTypeLibrary = NULL;
hr = LoadRegTypeLib(LIBID_DBF2ORALib, 1, 0, LANG_NEUTRAL, &pTypeLibrary);
if(SUCCEEDED(hr))
{
hr = pTypeLibrary->GetTypeInfoOfGuid(riid, &pTypeInfo);
if ( SUCCEEDED(hr) )
{
if (SUCCEEDED(pTypeInfo->GetContainingTypeLib( &pTypeLibrary,
&nIndex )))
{

hr = pTypeLibrary->GetDocumentation( nIndex, &bstrName,
&bstrDocString, &dwHelpContext, &bstrHelpFile );
if (SUCCEEDED(hr) )
{
// MessageBox(NULL, OLE2T(bstrName), "", MB_OK);
}
}
}

BSTR desc;
pEI->GetDescription(&desc);

char buff [1024];
WideCharToMultiByte(CP_ACP, NULL, desc, -1, buff, 1024, NULL, NULL);
MessageBox(NULL, _T(buff), W2CA(bstrDocString), MB_OK |
MB_SETFOREGROUND);
SysFreeString(desc);
// pEI->Release();
}
pTypeLibrary->Release();
}
pInterface->Release();
 
"Error("Your error message" , __uuidof(IMyinterface));" Doesn't give error
description either. I suspect that my interface was not registered for COM
exception. Thanks

Best Regards
Onega

Michael Nemtsev said:
Onega said:
Hi

I have problem raising COM exception with
support_error_info("IMyinterface"). ...
public IMyinterface
{

STDMETHODIMP Test(BSTR bsTestValue)
{
if(true)
{

Use ATL for rise error
Error("Your error message" , __uuidof(IMyinterface));

in client u could get your text error by this

CComQIPtr<ISupportErrorInfo> pISERPtr (pInterface);
//pInterface->QueryInterface(IID_ISupportErrorInfo, (void**)&pISER);
// Does this interface have COM exception support?
if(SUCCEEDED(pISERPtr->InterfaceSupportsErrorInfo(riid)))
{
if(SUCCEEDED(GetErrorInfo(NULL, &pEI)))
{
ITypeLib* pTypeLibrary = NULL;
hr = LoadRegTypeLib(LIBID_DBF2ORALib, 1, 0, LANG_NEUTRAL, &pTypeLibrary);
if(SUCCEEDED(hr))
{
hr = pTypeLibrary->GetTypeInfoOfGuid(riid, &pTypeInfo);
if ( SUCCEEDED(hr) )
{
if (SUCCEEDED(pTypeInfo->GetContainingTypeLib( &pTypeLibrary,
&nIndex )))
{

hr = pTypeLibrary->GetDocumentation( nIndex, &bstrName,
&bstrDocString, &dwHelpContext, &bstrHelpFile );
if (SUCCEEDED(hr) )
{
// MessageBox(NULL, OLE2T(bstrName), "", MB_OK);
}
}
}

BSTR desc;
pEI->GetDescription(&desc);

char buff [1024];
WideCharToMultiByte(CP_ACP, NULL, desc, -1, buff, 1024, NULL, NULL);
MessageBox(NULL, _T(buff), W2CA(bstrDocString), MB_OK |
MB_SETFOREGROUND);
SysFreeString(desc);
// pEI->Release();
}
pTypeLibrary->Release();
}
pInterface->Release();
 
Please see the post in microsoft.public.vc.atl that describe the steps to
regenerate my problem.
()
Best Regards
Onega
 
Have you tried deriving your com class from IDispatchImpl instead of the
interface?

class ATL_NO_VTABLE Something:
public IDispatchImpl<IMyinterface>
{

This will prevent the attribute provider from injecting its code. I had
similar problems where I could not get a detailed error description in a
script client. The above step solved the problem. I no routinely derive my
coclasses from IDispatchImpl<SomeItf>.
 
Back
Top