469,268 Members | 1,015 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,268 developers. It's quick & easy.

How to raise COM exception with support_error_info attribute ?

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
Nov 16 '05 #1
5 2313

"Onega" <On***@mvps.org> wrote in message
news:er**************@TK2MSFTNGP10.phx.gbl...
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();

Nov 16 '05 #2
"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" <la*****@mail.ru> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...

"Onega" <On***@mvps.org> wrote in message
news:er**************@TK2MSFTNGP10.phx.gbl...
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();

Nov 16 '05 #3
Please see the post in microsoft.public.vc.atl that describe the steps to
regenerate my problem.
(news:uU**************@TK2MSFTNGP10.phx.gbl )
Best Regards
Onega

"Onega" <On***@mvps.org> wrote in message
news:%2******************@tk2msftngp13.phx.gbl...
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

Nov 16 '05 #4
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>.

"Onega" <On***@mvps.org> wrote in message
news:%2******************@tk2msftngp13.phx.gbl...
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

Nov 16 '05 #5
Thanks a lot to Dirk. It works now.

Best Regards
Onega

"Dirk" <dirk.kapusta@reply_in_.newsgroup> wrote in message
news:uu**************@TK2MSFTNGP11.phx.gbl...
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>.

"Onega" <On***@mvps.org> wrote in message
news:%2******************@tk2msftngp13.phx.gbl...
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


Nov 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.