473,386 Members | 1,748 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,386 software developers and data experts.

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 2424

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

Similar topics

3
by: Dmitry | last post by:
Hi, I have defined interface for COM components which inludes an argument being filled with additional error info, if such occurs. If inside I raise COM Error, I populate that parameter. In COM...
3
by: Dmitry | last post by:
Hi, I have defined interface for COM components which inludes an argument being filled with additional error info, if such occurs. If inside I raise COM Error, I populate that parameter. In COM...
3
by: Dmitry | last post by:
Hi, I have defined interface for COM components which inludes an argument being filled with additional error info, if such occurs. If inside I raise COM Error, I populate that parameter. In COM...
14
by: Rafe | last post by:
Hi, I've encountered a problem which is making debugging less obvious than it should be. The @property decorator doesn't always raise exceptions. It seems like it is bound to the class but...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.