Errors from C++ -> VB 
Author Message
 Errors from C++ -> VB

Hi all, I am writing a VC++ ATL dll that will be called from a VB exe on
Win2k.  I have gotten everything to work except for raising errors back up
to VB.  For instance, at the beginning of my VC++ dll I am checking to make
sure the parameters that I am passed are acceptable.  If they aren't I want
to raise a custom error back to my VB app that says something like "param 1
is invalid".  I am trying to use _com_raise_error(hr) and/or trying to use
throw _com_error.  In both of my samples I get an "Unhandled exception in
Project1.exe (KERNEL32.DLL):E06D7363: Microsoft C++ Exception"  Project1.exe
is my VB app.  Does anyone know what I am doing OR a better way to do it?  I
just want to be able to catch an error in my VB app in the On Error Goto
construct and pass it some meaningful information (ala an error
Description).

Also, I do implement ISupportErrorInfoImpl<...>.  Do I need to do that?

I've tried:
           HRESULT hr = ERROR_INVALID_DATA;
           _com_raise_error(hr);
And I've tried:

                HRESULT hr = CoInitialize( NULL );
                ICreateErrorInfo *pcerrinfo;
                IErrorInfo *perrinfo;

                hr = CreateErrorInfo(&pcerrinfo);
                pcerrinfo->SetDescription((_bstr_t)"This is my error");
                hr = pcerrinfo->QueryInterface(IID_IErrorInfo, (LPVOID FAR*)
&perrinfo);
                if (SUCCEEDED(hr))

                        pcerrinfo->Release();
                        throw _com_error(E_INVALIDARG,perrinfo);
                }
                throw _com_error(E_INVALIDARG,perrinfo);
                (void) CoUninitialize();

Thanks a lot.

Greg



Sat, 11 Oct 2003 18:33:12 GMT  
 Errors from C++ -> VB
    All you need is just to return appropriate HRESULT from your ActiveX
method. If HRESULT has severity set to SEVERITY_ERROR then VB treats this
retcode as an error and then you can handle this error with On Error...
    And of course you can't pass an error code to VB via throwing an
exception, because it is a C++ exception and it should be handled whithin
your C++ code. You have to catch all exceptions in your code and translate
them into appropriate HRESULTs and pass them back to the calling VB code.

--
alexk

---
To reply by mail remove --NOSPAM


Quote:
> Hi all, I am writing a VC++ ATL dll that will be called from a VB exe on
> Win2k.  I have gotten everything to work except for raising errors back up
> to VB.  For instance, at the beginning of my VC++ dll I am checking to
make
> sure the parameters that I am passed are acceptable.  If they aren't I
want
> to raise a custom error back to my VB app that says something like "param
1
> is invalid".  I am trying to use _com_raise_error(hr) and/or trying to use
> throw _com_error.  In both of my samples I get an "Unhandled exception in
> Project1.exe (KERNEL32.DLL):E06D7363: Microsoft C++ Exception"
Project1.exe
> is my VB app.  Does anyone know what I am doing OR a better way to do it?
I
> just want to be able to catch an error in my VB app in the On Error Goto
> construct and pass it some meaningful information (ala an error
> Description).



Sat, 11 Oct 2003 06:59:09 GMT  
 Errors from C++ -> VB
Do you have any samples of this?  I've tried return S_FALSE; but that
doesn't work.  How do I 'create' my HRESULT?  How would I associate a
description with the hr?  Isn't there a way to throw a COM exception that VB
as a COM based language would understand?

Thanks.


Quote:
>     All you need is just to return appropriate HRESULT from your ActiveX
> method. If HRESULT has severity set to SEVERITY_ERROR then VB treats this
> retcode as an error and then you can handle this error with On Error...
>     And of course you can't pass an error code to VB via throwing an
> exception, because it is a C++ exception and it should be handled whithin
> your C++ code. You have to catch all exceptions in your code and translate
> them into appropriate HRESULTs and pass them back to the calling VB code.

> --
> alexk

> ---
> To reply by mail remove --NOSPAM



> > Hi all, I am writing a VC++ ATL dll that will be called from a VB exe on
> > Win2k.  I have gotten everything to work except for raising errors back
up
> > to VB.  For instance, at the beginning of my VC++ dll I am checking to
> make
> > sure the parameters that I am passed are acceptable.  If they aren't I
> want
> > to raise a custom error back to my VB app that says something like
"param
> 1
> > is invalid".  I am trying to use _com_raise_error(hr) and/or trying to
use
> > throw _com_error.  In both of my samples I get an "Unhandled exception
in
> > Project1.exe (KERNEL32.DLL):E06D7363: Microsoft C++ Exception"
> Project1.exe
> > is my VB app.  Does anyone know what I am doing OR a better way to do
it?
> I
> > just want to be able to catch an error in my VB app in the On Error Goto
> > construct and pass it some meaningful information (ala an error
> > Description).



Sat, 11 Oct 2003 19:07:49 GMT  
 Errors from C++ -> VB
OK, I figured out how to 'create' the hr using MAKE_HRESULT()

I still don't know how I would make that error meaningful in VB.  When I
return my hr set as SEVERITY_ERROR I just get method ~ of ~ failed in VB.
Do I need to enumerate errors in my lib or something?  Any samples would be
great.

Thanks.


Quote:
> Do you have any samples of this?  I've tried return S_FALSE; but that
> doesn't work.  How do I 'create' my HRESULT?  How would I associate a
> description with the hr?  Isn't there a way to throw a COM exception that
VB
> as a COM based language would understand?

> Thanks.



> >     All you need is just to return appropriate HRESULT from your ActiveX
> > method. If HRESULT has severity set to SEVERITY_ERROR then VB treats
this
> > retcode as an error and then you can handle this error with On Error...
> >     And of course you can't pass an error code to VB via throwing an
> > exception, because it is a C++ exception and it should be handled
whithin
> > your C++ code. You have to catch all exceptions in your code and
translate
> > them into appropriate HRESULTs and pass them back to the calling VB
code.

> > --
> > alexk

> > ---
> > To reply by mail remove --NOSPAM



> > > Hi all, I am writing a VC++ ATL dll that will be called from a VB exe
on
> > > Win2k.  I have gotten everything to work except for raising errors
back
> up
> > > to VB.  For instance, at the beginning of my VC++ dll I am checking to
> > make
> > > sure the parameters that I am passed are acceptable.  If they aren't I
> > want
> > > to raise a custom error back to my VB app that says something like
> "param
> > 1
> > > is invalid".  I am trying to use _com_raise_error(hr) and/or trying to
> use
> > > throw _com_error.  In both of my samples I get an "Unhandled exception
> in
> > > Project1.exe (KERNEL32.DLL):E06D7363: Microsoft C++ Exception"
> > Project1.exe
> > > is my VB app.  Does anyone know what I am doing OR a better way to do
> it?
> > I
> > > just want to be able to catch an error in my VB app in the On Error
Goto
> > > construct and pass it some meaningful information (ala an error
> > > Description).



Sat, 11 Oct 2003 19:16:46 GMT  
 Errors from C++ -> VB
Hello Jai'rus!

Why do you call CoInitialize? It's VB tasks, and you shouldn't do it inside
object code.

Also I didn't see "catch" statements which correspond to "throw" one in your
code...if you don't handle them, then system catches it w/ well known
"Unhandled exception in ..." dialog...

ATL has helpers which initialize error information. Look at
CComCoClass::Error and AtlReportError functions.

Regarding samples: look at that:

"BEEPER: Demonstrates a Tearoff Interface"
http://www.*-*-*.com/
beeper.htm
(more precisely CBeeper::Beep())

--
Best regards,
Vadim Melnik,
{*filter*} Consultant.
_____________________________
http://www.*-*-*.com/


Quote:
> Hi all, I am writing a VC++ ATL dll that will be called from a VB exe on
> Win2k.  I have gotten everything to work except for raising errors back up
> to VB.  For instance, at the beginning of my VC++ dll I am checking to
make
> sure the parameters that I am passed are acceptable.  If they aren't I
want
> to raise a custom error back to my VB app that says something like "param
1
> is invalid".  I am trying to use _com_raise_error(hr) and/or trying to use
> throw _com_error.  In both of my samples I get an "Unhandled exception in
> Project1.exe (KERNEL32.DLL):E06D7363: Microsoft C++ Exception"
Project1.exe
> is my VB app.  Does anyone know what I am doing OR a better way to do it?
I
> just want to be able to catch an error in my VB app in the On Error Goto
> construct and pass it some meaningful information (ala an error
> Description).

> Also, I do implement ISupportErrorInfoImpl<...>.  Do I need to do that?

> I've tried:
>            HRESULT hr = ERROR_INVALID_DATA;
>            _com_raise_error(hr);
> And I've tried:

>                 HRESULT hr = CoInitialize( NULL );
>                 ICreateErrorInfo *pcerrinfo;
>                 IErrorInfo *perrinfo;

>                 hr = CreateErrorInfo(&pcerrinfo);
>                 pcerrinfo->SetDescription((_bstr_t)"This is my error");
>                 hr = pcerrinfo->QueryInterface(IID_IErrorInfo, (LPVOID
FAR*)
> &perrinfo);
>                 if (SUCCEEDED(hr))

>                         pcerrinfo->Release();
>                         throw _com_error(E_INVALIDARG,perrinfo);
>                 }
>                 throw _com_error(E_INVALIDARG,perrinfo);
>                 (void) CoUninitialize();

> Thanks a lot.

> Greg



Sat, 11 Oct 2003 07:47:29 GMT  
 Errors from C++ -> VB
That is called Automation rich exception information, but really has
nothing to do with exceptions... Basically, you have to implement
ISupportErrorInfo on the object called by VB, have a coclass for it
in the type library (and corespondingly a CLSID) and report the
error via SetErrorInfo and returning a failure HRESULT. ATL has
helpers for this: CComCoClass::Error and AtlReportError.

BTW, the HRESULT cannot be a success, other than S_OK! S_FALSE
is a success HRESULT and is therefore illegal. This is a limitation
of using dual interfaces. However, VB doesn't understand success
HRESULTs even in non-dual interfaces...

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD

MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================


Quote:
> OK, I figured out how to 'create' the hr using MAKE_HRESULT()

> I still don't know how I would make that error meaningful in VB.  When I
> return my hr set as SEVERITY_ERROR I just get method ~ of ~ failed in VB.
> Do I need to enumerate errors in my lib or something?  Any samples would
be
> great.

> Thanks.



> > Do you have any samples of this?  I've tried return S_FALSE; but that
> > doesn't work.  How do I 'create' my HRESULT?  How would I associate a
> > description with the hr?  Isn't there a way to throw a COM exception
that
> VB
> > as a COM based language would understand?

> > Thanks.



> > >     All you need is just to return appropriate HRESULT from your
ActiveX
> > > method. If HRESULT has severity set to SEVERITY_ERROR then VB treats
> this
> > > retcode as an error and then you can handle this error with On
Error...
> > >     And of course you can't pass an error code to VB via throwing an
> > > exception, because it is a C++ exception and it should be handled
> whithin
> > > your C++ code. You have to catch all exceptions in your code and
> translate
> > > them into appropriate HRESULTs and pass them back to the calling VB
> code.

> > > --
> > > alexk

> > > ---
> > > To reply by mail remove --NOSPAM



> > > > Hi all, I am writing a VC++ ATL dll that will be called from a VB
exe
> on
> > > > Win2k.  I have gotten everything to work except for raising errors
> back
> > up
> > > > to VB.  For instance, at the beginning of my VC++ dll I am checking
to
> > > make
> > > > sure the parameters that I am passed are acceptable.  If they aren't
I
> > > want
> > > > to raise a custom error back to my VB app that says something like
> > "param
> > > 1
> > > > is invalid".  I am trying to use _com_raise_error(hr) and/or trying
to
> > use
> > > > throw _com_error.  In both of my samples I get an "Unhandled
exception
> > in
> > > > Project1.exe (KERNEL32.DLL):E06D7363: Microsoft C++ Exception"
> > > Project1.exe
> > > > is my VB app.  Does anyone know what I am doing OR a better way to
do
> > it?
> > > I
> > > > just want to be able to catch an error in my VB app in the On Error
> Goto
> > > > construct and pass it some meaningful information (ala an error
> > > > Description).



Sat, 11 Oct 2003 08:23:02 GMT  
 Errors from C++ -> VB

Quote:
> Do you have any samples of this?  I've tried return S_FALSE; but that
> doesn't work.  How do I 'create' my HRESULT?  How would I associate a
> description with the hr?  Isn't there a way to throw a COM exception that
VB
> as a COM based language would understand?

Return E_INVALIDARG. S_FALSE is a success code, not an error one...

Christian.



Sat, 11 Oct 2003 17:47:18 GMT  
 Errors from C++ -> VB
Thanks for all of the help everyone.  Still not sure how to make this work
the way I'm expecting.

When I do this:
    return Error(L"Too many beeps");
in my code I do get an error back to my VB code but the description is still
"Method ~ of object ~ failed.  How can I make Err.Description in VB be = to
"Too many beeps"?


Quote:
> Hello Jai'rus!

> Why do you call CoInitialize? It's VB tasks, and you shouldn't do it
inside
> object code.

> Also I didn't see "catch" statements which correspond to "throw" one in
your
> code...if you don't handle them, then system catches it w/ well known
> "Unhandled exception in ..." dialog...

> ATL has helpers which initialize error information. Look at
> CComCoClass::Error and AtlReportError functions.

> Regarding samples: look at that:

> "BEEPER: Demonstrates a Tearoff Interface"

http://www.*-*-*.com/

- Show quoted text -

Quote:
> beeper.htm
> (more precisely CBeeper::Beep())

> --
> Best regards,
> Vadim Melnik,
> {*filter*} Consultant.
> _____________________________
> http://www.*-*-*.com/



> > Hi all, I am writing a VC++ ATL dll that will be called from a VB exe on
> > Win2k.  I have gotten everything to work except for raising errors back
up
> > to VB.  For instance, at the beginning of my VC++ dll I am checking to
> make
> > sure the parameters that I am passed are acceptable.  If they aren't I
> want
> > to raise a custom error back to my VB app that says something like
"param
> 1
> > is invalid".  I am trying to use _com_raise_error(hr) and/or trying to
use
> > throw _com_error.  In both of my samples I get an "Unhandled exception
in
> > Project1.exe (KERNEL32.DLL):E06D7363: Microsoft C++ Exception"
> Project1.exe
> > is my VB app.  Does anyone know what I am doing OR a better way to do
it?
> I
> > just want to be able to catch an error in my VB app in the On Error Goto
> > construct and pass it some meaningful information (ala an error
> > Description).

> > Also, I do implement ISupportErrorInfoImpl<...>.  Do I need to do that?

> > I've tried:
> >            HRESULT hr = ERROR_INVALID_DATA;
> >            _com_raise_error(hr);
> > And I've tried:

> >                 HRESULT hr = CoInitialize( NULL );
> >                 ICreateErrorInfo *pcerrinfo;
> >                 IErrorInfo *perrinfo;

> >                 hr = CreateErrorInfo(&pcerrinfo);
> >                 pcerrinfo->SetDescription((_bstr_t)"This is my error");
> >                 hr = pcerrinfo->QueryInterface(IID_IErrorInfo, (LPVOID
> FAR*)
> > &perrinfo);
> >                 if (SUCCEEDED(hr))

> >                         pcerrinfo->Release();
> >                         throw _com_error(E_INVALIDARG,perrinfo);
> >                 }
> >                 throw _com_error(E_INVALIDARG,perrinfo);
> >                 (void) CoUninitialize();

> > Thanks a lot.

> > Greg



Sun, 12 Oct 2003 13:51:46 GMT  
 Errors from C++ -> VB
Greets,

    Use the CreateErrorInfo() API function in order to get an interface
pointer to an ICreateErrorInfo object.  Call the SetDescription(),
SetGUID(), SetHelpContext() and SetHelpFile() methods as appropriate,
SetDescription() will probably be of interest to you.  Next, call
QueryInterface() with the IID_IErrorInfo UUID in order to get the IErrorInfo
object that has been set up through the method calls to ICreateErrorInfo.
Then, use the SetErrorInfo() API function to set up the error context that
will be handed to Visual Basic.  Finally, return an HRESULT from the method
call that is indicative of the error.

Regards,

Joe


Quote:
> Thanks for all of the help everyone.  Still not sure how to make this work
> the way I'm expecting.

> When I do this:
>     return Error(L"Too many beeps");
> in my code I do get an error back to my VB code but the description is
still
> "Method ~ of object ~ failed.  How can I make Err.Description in VB be =
to
> "Too many beeps"?



> > Hello Jai'rus!

> > Why do you call CoInitialize? It's VB tasks, and you shouldn't do it
> inside
> > object code.

> > Also I didn't see "catch" statements which correspond to "throw" one in
> your
> > code...if you don't handle them, then system catches it w/ well known
> > "Unhandled exception in ..." dialog...

> > ATL has helpers which initialize error information. Look at
> > CComCoClass::Error and AtlReportError functions.

> > Regarding samples: look at that:

> > "BEEPER: Demonstrates a Tearoff Interface"

http://www.*-*-*.com/

- Show quoted text -

Quote:
> > beeper.htm
> > (more precisely CBeeper::Beep())

> > --
> > Best regards,
> > Vadim Melnik,
> > {*filter*} Consultant.
> > _____________________________
> > http://www.*-*-*.com/



> > > Hi all, I am writing a VC++ ATL dll that will be called from a VB exe
on
> > > Win2k.  I have gotten everything to work except for raising errors
back
> up
> > > to VB.  For instance, at the beginning of my VC++ dll I am checking to
> > make
> > > sure the parameters that I am passed are acceptable.  If they aren't I
> > want
> > > to raise a custom error back to my VB app that says something like
> "param
> > 1
> > > is invalid".  I am trying to use _com_raise_error(hr) and/or trying to
> use
> > > throw _com_error.  In both of my samples I get an "Unhandled exception
> in
> > > Project1.exe (KERNEL32.DLL):E06D7363: Microsoft C++ Exception"
> > Project1.exe
> > > is my VB app.  Does anyone know what I am doing OR a better way to do
> it?
> > I
> > > just want to be able to catch an error in my VB app in the On Error
Goto
> > > construct and pass it some meaningful information (ala an error
> > > Description).

> > > Also, I do implement ISupportErrorInfoImpl<...>.  Do I need to do
that?

> > > I've tried:
> > >            HRESULT hr = ERROR_INVALID_DATA;
> > >            _com_raise_error(hr);
> > > And I've tried:

> > >                 HRESULT hr = CoInitialize( NULL );
> > >                 ICreateErrorInfo *pcerrinfo;
> > >                 IErrorInfo *perrinfo;

> > >                 hr = CreateErrorInfo(&pcerrinfo);
> > >                 pcerrinfo->SetDescription((_bstr_t)"This is my
error");
> > >                 hr = pcerrinfo->QueryInterface(IID_IErrorInfo, (LPVOID
> > FAR*)
> > > &perrinfo);
> > >                 if (SUCCEEDED(hr))

> > >                         pcerrinfo->Release();
> > >                         throw _com_error(E_INVALIDARG,perrinfo);
> > >                 }
> > >                 throw _com_error(E_INVALIDARG,perrinfo);
> > >                 (void) CoUninitialize();

> > > Thanks a lot.

> > > Greg



Sun, 12 Oct 2003 02:18:33 GMT  
 Errors from C++ -> VB
Joe et al, I tired using the API and have gotten the same result.  In VB I
do msgbox("Desc: " & Err.Description) and still get Method ~ of object ~
failed.  What am I doing wrong?

Here's the code I'm using.

                ICreateErrorInfo *pcerrinfo;
                IErrorInfo *perrinfo;

                hr = CreateErrorInfo(&pcerrinfo);
                hr = pcerrinfo->SetDescription(L"This is my error");

                hr = pcerrinfo->QueryInterface(IID_IErrorInfo, (LPVOID FAR*)
&perrinfo);
                if (SUCCEEDED(hr))

                        SetErrorInfo(0, perrinfo);
                        perrinfo->Release();
                }
                pcerrinfo->Release();

                return E_FAIL;


Quote:
> Greets,

>     Use the CreateErrorInfo() API function in order to get an interface
> pointer to an ICreateErrorInfo object.  Call the SetDescription(),
> SetGUID(), SetHelpContext() and SetHelpFile() methods as appropriate,
> SetDescription() will probably be of interest to you.  Next, call
> QueryInterface() with the IID_IErrorInfo UUID in order to get the
IErrorInfo
> object that has been set up through the method calls to ICreateErrorInfo.
> Then, use the SetErrorInfo() API function to set up the error context that
> will be handed to Visual Basic.  Finally, return an HRESULT from the
method
> call that is indicative of the error.

> Regards,

> Joe



> > Thanks for all of the help everyone.  Still not sure how to make this
work
> > the way I'm expecting.

> > When I do this:
> >     return Error(L"Too many beeps");
> > in my code I do get an error back to my VB code but the description is
> still
> > "Method ~ of object ~ failed.  How can I make Err.Description in VB be =
> to
> > "Too many beeps"?



> > > Hello Jai'rus!

> > > Why do you call CoInitialize? It's VB tasks, and you shouldn't do it
> > inside
> > > object code.

> > > Also I didn't see "catch" statements which correspond to "throw" one
in
> > your
> > > code...if you don't handle them, then system catches it w/ well known
> > > "Unhandled exception in ..." dialog...

> > > ATL has helpers which initialize error information. Look at
> > > CComCoClass::Error and AtlReportError functions.

> > > Regarding samples: look at that:

> > > "BEEPER: Demonstrates a Tearoff Interface"

http://www.*-*-*.com/

- Show quoted text -

Quote:
> > > beeper.htm
> > > (more precisely CBeeper::Beep())

> > > --
> > > Best regards,
> > > Vadim Melnik,
> > > {*filter*} Consultant.
> > > _____________________________
> > > http://www.*-*-*.com/



> > > > Hi all, I am writing a VC++ ATL dll that will be called from a VB
exe
> on
> > > > Win2k.  I have gotten everything to work except for raising errors
> back
> > up
> > > > to VB.  For instance, at the beginning of my VC++ dll I am checking
to
> > > make
> > > > sure the parameters that I am passed are acceptable.  If they aren't
I
> > > want
> > > > to raise a custom error back to my VB app that says something like
> > "param
> > > 1
> > > > is invalid".  I am trying to use _com_raise_error(hr) and/or trying
to
> > use
> > > > throw _com_error.  In both of my samples I get an "Unhandled
exception
> > in
> > > > Project1.exe (KERNEL32.DLL):E06D7363: Microsoft C++ Exception"
> > > Project1.exe
> > > > is my VB app.  Does anyone know what I am doing OR a better way to
do
> > it?
> > > I
> > > > just want to be able to catch an error in my VB app in the On Error
> Goto
> > > > construct and pass it some meaningful information (ala an error
> > > > Description).

> > > > Also, I do implement ISupportErrorInfoImpl<...>.  Do I need to do
> that?

> > > > I've tried:
> > > >            HRESULT hr = ERROR_INVALID_DATA;
> > > >            _com_raise_error(hr);
> > > > And I've tried:

> > > >                 HRESULT hr = CoInitialize( NULL );
> > > >                 ICreateErrorInfo *pcerrinfo;
> > > >                 IErrorInfo *perrinfo;

> > > >                 hr = CreateErrorInfo(&pcerrinfo);
> > > >                 pcerrinfo->SetDescription((_bstr_t)"This is my
> error");
> > > >                 hr = pcerrinfo->QueryInterface(IID_IErrorInfo,
(LPVOID
> > > FAR*)
> > > > &perrinfo);
> > > >                 if (SUCCEEDED(hr))

> > > >                         pcerrinfo->Release();
> > > >                         throw _com_error(E_INVALIDARG,perrinfo);
> > > >                 }
> > > >                 throw _com_error(E_INVALIDARG,perrinfo);
> > > >                 (void) CoUninitialize();

> > > > Thanks a lot.

> > > > Greg



Sun, 12 Oct 2003 14:52:33 GMT  
 Errors from C++ -> VB
Greets,

    Have you tried using the SetGUID() method on ICreateErrorInfo in order
to set the GUID of your interface that is returning the error?  (or using
GUID_NULL if from the system?)  Are you also implementing ISupportsErrorInfo
for your object?

Regards,

Joe


Quote:
> Joe et al, I tired using the API and have gotten the same result.  In VB I
> do msgbox("Desc: " & Err.Description) and still get Method ~ of object ~
> failed.  What am I doing wrong?

> Here's the code I'm using.

>                 ICreateErrorInfo *pcerrinfo;
>                 IErrorInfo *perrinfo;

>                 hr = CreateErrorInfo(&pcerrinfo);
>                 hr = pcerrinfo->SetDescription(L"This is my error");

>                 hr = pcerrinfo->QueryInterface(IID_IErrorInfo, (LPVOID
FAR*)
> &perrinfo);
>                 if (SUCCEEDED(hr))

>                         SetErrorInfo(0, perrinfo);
>                         perrinfo->Release();
>                 }
>                 pcerrinfo->Release();

>                 return E_FAIL;



> > Greets,

> >     Use the CreateErrorInfo() API function in order to get an interface
> > pointer to an ICreateErrorInfo object.  Call the SetDescription(),
> > SetGUID(), SetHelpContext() and SetHelpFile() methods as appropriate,
> > SetDescription() will probably be of interest to you.  Next, call
> > QueryInterface() with the IID_IErrorInfo UUID in order to get the
> IErrorInfo
> > object that has been set up through the method calls to
ICreateErrorInfo.
> > Then, use the SetErrorInfo() API function to set up the error context
that
> > will be handed to Visual Basic.  Finally, return an HRESULT from the
> method
> > call that is indicative of the error.

> > Regards,

> > Joe



> > > Thanks for all of the help everyone.  Still not sure how to make this
> work
> > > the way I'm expecting.

> > > When I do this:
> > >     return Error(L"Too many beeps");
> > > in my code I do get an error back to my VB code but the description is
> > still
> > > "Method ~ of object ~ failed.  How can I make Err.Description in VB be
=
> > to
> > > "Too many beeps"?



> > > > Hello Jai'rus!

> > > > Why do you call CoInitialize? It's VB tasks, and you shouldn't do it
> > > inside
> > > > object code.

> > > > Also I didn't see "catch" statements which correspond to "throw" one
> in
> > > your
> > > > code...if you don't handle them, then system catches it w/ well
known
> > > > "Unhandled exception in ..." dialog...

> > > > ATL has helpers which initialize error information. Look at
> > > > CComCoClass::Error and AtlReportError functions.

> > > > Regarding samples: look at that:

> > > > "BEEPER: Demonstrates a Tearoff Interface"

http://www.*-*-*.com/

- Show quoted text -

Quote:
> > > > beeper.htm
> > > > (more precisely CBeeper::Beep())

> > > > --
> > > > Best regards,
> > > > Vadim Melnik,
> > > > {*filter*} Consultant.
> > > > _____________________________
> > > > http://www.*-*-*.com/



> > > > > Hi all, I am writing a VC++ ATL dll that will be called from a VB
> exe
> > on
> > > > > Win2k.  I have gotten everything to work except for raising errors
> > back
> > > up
> > > > > to VB.  For instance, at the beginning of my VC++ dll I am
checking
> to
> > > > make
> > > > > sure the parameters that I am passed are acceptable.  If they
aren't
> I
> > > > want
> > > > > to raise a custom error back to my VB app that says something like
> > > "param
> > > > 1
> > > > > is invalid".  I am trying to use _com_raise_error(hr) and/or
trying
> to
> > > use
> > > > > throw _com_error.  In both of my samples I get an "Unhandled
> exception
> > > in
> > > > > Project1.exe (KERNEL32.DLL):E06D7363: Microsoft C++ Exception"
> > > > Project1.exe
> > > > > is my VB app.  Does anyone know what I am doing OR a better way to
> do
> > > it?
> > > > I
> > > > > just want to be able to catch an error in my VB app in the On
Error
> > Goto
> > > > > construct and pass it some meaningful information (ala an error
> > > > > Description).

> > > > > Also, I do implement ISupportErrorInfoImpl<...>.  Do I need to do
> > that?

> > > > > I've tried:
> > > > >            HRESULT hr = ERROR_INVALID_DATA;
> > > > >            _com_raise_error(hr);
> > > > > And I've tried:

> > > > >                 HRESULT hr = CoInitialize( NULL );
> > > > >                 ICreateErrorInfo *pcerrinfo;
> > > > >                 IErrorInfo *perrinfo;

> > > > >                 hr = CreateErrorInfo(&pcerrinfo);
> > > > >                 pcerrinfo->SetDescription((_bstr_t)"This is my
> > error");
> > > > >                 hr = pcerrinfo->QueryInterface(IID_IErrorInfo,
> (LPVOID
> > > > FAR*)
> > > > > &perrinfo);
> > > > >                 if (SUCCEEDED(hr))

> > > > >                         pcerrinfo->Release();
> > > > >                         throw _com_error(E_INVALIDARG,perrinfo);
> > > > >                 }
> > > > >                 throw _com_error(E_INVALIDARG,perrinfo);
> > > > >                 (void) CoUninitialize();

> > > > > Thanks a lot.

> > > > > Greg



Sun, 12 Oct 2003 03:13:14 GMT  
 Errors from C++ -> VB
Yea, I also tried the following code with SetGUID.
...
hr = CreateErrorInfo(&pcerrinfo);
hr = pcerrinfo->SetGUID(__UUIDOF(ITTS));
hr = pcerrinfo->SetDescription(L"This is my error");
hr = pcerrinfo->QueryInterface(IID_IErrorInfo, (LPVOID FAR*) &perrinfo);
...

I also implement ISupportsErrorInfo like this:  Do I need to do anything
else or declare this differently?
class ATL_NO_VTABLE CTTS :
        public CComObjectRootEx<CComSingleThreadModel>,
        public CComCoClass<CTTS, &CLSID_TTS>,
        public IDispatchImpl<ITTS, &IID_ITTS, &LIBID_BHFONIXLib>,
        public ISupportErrorInfoImpl< &IID_ITTS >

...


Quote:
> Greets,

>     Have you tried using the SetGUID() method on ICreateErrorInfo in order
> to set the GUID of your interface that is returning the error?  (or using
> GUID_NULL if from the system?)  Are you also implementing
ISupportsErrorInfo
> for your object?

> Regards,

> Joe



> > Joe et al, I tired using the API and have gotten the same result.  In VB
I
> > do msgbox("Desc: " & Err.Description) and still get Method ~ of object ~
> > failed.  What am I doing wrong?

> > Here's the code I'm using.

> >                 ICreateErrorInfo *pcerrinfo;
> >                 IErrorInfo *perrinfo;

> >                 hr = CreateErrorInfo(&pcerrinfo);
> >                 hr = pcerrinfo->SetDescription(L"This is my error");

> >                 hr = pcerrinfo->QueryInterface(IID_IErrorInfo, (LPVOID
> FAR*)
> > &perrinfo);
> >                 if (SUCCEEDED(hr))

> >                         SetErrorInfo(0, perrinfo);
> >                         perrinfo->Release();
> >                 }
> >                 pcerrinfo->Release();

> >                 return E_FAIL;



> > > Greets,

> > >     Use the CreateErrorInfo() API function in order to get an
interface
> > > pointer to an ICreateErrorInfo object.  Call the SetDescription(),
> > > SetGUID(), SetHelpContext() and SetHelpFile() methods as appropriate,
> > > SetDescription() will probably be of interest to you.  Next, call
> > > QueryInterface() with the IID_IErrorInfo UUID in order to get the
> > IErrorInfo
> > > object that has been set up through the method calls to
> ICreateErrorInfo.
> > > Then, use the SetErrorInfo() API function to set up the error context
> that
> > > will be handed to Visual Basic.  Finally, return an HRESULT from the
> > method
> > > call that is indicative of the error.

> > > Regards,

> > > Joe



> > > > Thanks for all of the help everyone.  Still not sure how to make
this
> > work
> > > > the way I'm expecting.

> > > > When I do this:
> > > >     return Error(L"Too many beeps");
> > > > in my code I do get an error back to my VB code but the description
is
> > > still
> > > > "Method ~ of object ~ failed.  How can I make Err.Description in VB
be
> =
> > > to
> > > > "Too many beeps"?



> > > > > Hello Jai'rus!

> > > > > Why do you call CoInitialize? It's VB tasks, and you shouldn't do
it
> > > > inside
> > > > > object code.

> > > > > Also I didn't see "catch" statements which correspond to "throw"
one
> > in
> > > > your
> > > > > code...if you don't handle them, then system catches it w/ well
> known
> > > > > "Unhandled exception in ..." dialog...

> > > > > ATL has helpers which initialize error information. Look at
> > > > > CComCoClass::Error and AtlReportError functions.

> > > > > Regarding samples: look at that:

> > > > > "BEEPER: Demonstrates a Tearoff Interface"

http://www.*-*-*.com/

- Show quoted text -

Quote:
> > > > > beeper.htm
> > > > > (more precisely CBeeper::Beep())

> > > > > --
> > > > > Best regards,
> > > > > Vadim Melnik,
> > > > > {*filter*} Consultant.
> > > > > _____________________________
> > > > > http://www.*-*-*.com/



> > > > > > Hi all, I am writing a VC++ ATL dll that will be called from a
VB
> > exe
> > > on
> > > > > > Win2k.  I have gotten everything to work except for raising
errors
> > > back
> > > > up
> > > > > > to VB.  For instance, at the beginning of my VC++ dll I am
> checking
> > to
> > > > > make
> > > > > > sure the parameters that I am passed are acceptable.  If they
> aren't
> > I
> > > > > want
> > > > > > to raise a custom error back to my VB app that says something
like
> > > > "param
> > > > > 1
> > > > > > is invalid".  I am trying to use _com_raise_error(hr) and/or
> trying
> > to
> > > > use
> > > > > > throw _com_error.  In both of my samples I get an "Unhandled
> > exception
> > > > in
> > > > > > Project1.exe (KERNEL32.DLL):E06D7363: Microsoft C++ Exception"
> > > > > Project1.exe
> > > > > > is my VB app.  Does anyone know what I am doing OR a better way
to
> > do
> > > > it?
> > > > > I
> > > > > > just want to be able to catch an error in my VB app in the On
> Error
> > > Goto
> > > > > > construct and pass it some meaningful information (ala an error
> > > > > > Description).

> > > > > > Also, I do implement ISupportErrorInfoImpl<...>.  Do I need to
do
> > > that?

> > > > > > I've tried:
> > > > > >            HRESULT hr = ERROR_INVALID_DATA;
> > > > > >            _com_raise_error(hr);
> > > > > > And I've tried:

> > > > > >                 HRESULT hr = CoInitialize( NULL );
> > > > > >                 ICreateErrorInfo *pcerrinfo;
> > > > > >                 IErrorInfo *perrinfo;

> > > > > >                 hr = CreateErrorInfo(&pcerrinfo);
> > > > > >                 pcerrinfo->SetDescription((_bstr_t)"This is my
> > > error");
> > > > > >                 hr = pcerrinfo->QueryInterface(IID_IErrorInfo,
> > (LPVOID
> > > > > FAR*)
> > > > > > &perrinfo);
> > > > > >                 if (SUCCEEDED(hr))

> > > > > >                         pcerrinfo->Release();
> > > > > >                         throw _com_error(E_INVALIDARG,perrinfo);
> > > > > >                 }
> > > > > >                 throw _com_error(E_INVALIDARG,perrinfo);
> > > > > >                 (void) CoUninitialize();

> > > > > > Thanks a lot.

> > > > > > Greg



Sun, 12 Oct 2003 16:18:48 GMT  
 Errors from C++ -> VB
Hello Jai'rus,

Quote:
> Thanks for all of the help everyone.  Still not sure how to make this work
> the way I'm expecting.

> When I do this:
>     return Error(L"Too many beeps");
> in my code I do get an error back to my VB code but the description is
still
> "Method ~ of object ~ failed.  How can I make Err.Description in VB be =
to
> "Too many beeps"?

How do you handle exception in VB?
Below html sample, which uses beeper object and catches exception,
on my PC it works fine.

<html>

<script language=jscript>
function beepJava()
{
 try
 {
  beeperobj.beep();
 } catch(e)
 {
  alert("Error, description="+e.description);
 }

Quote:
}

</script>

<script language=VBScript>
 sub beepVB
  on error resume next
  beeperobj.beep()
  if err.number <> 0 then
   msgbox "Error, description=" & err.description
   err.clear
  end if
 end sub
</script>

<body>
 <object classid="clsid:6384d586-0fdb-11cf-8700-00aa0053006d"
id=beeperobj></object>
 <input type=button value="Test Java Beep" onclick="beepJava();">
 <input type=button value="Test VB Beep" onclick="beepVB();">
</body>
</html>

--
Best regards,
Vadim Melnik,
{*filter*} Consultant.
_____________________________
http://www.*-*-*.com/



Sun, 12 Oct 2003 05:24:31 GMT  
 Errors from C++ -> VB
OK, I just recompiled my VB app and everything works.  Both ATLReportError
and the CreateErrorInfo code.  Thanks a lot for all of your help.

Greg


Quote:
> Hello Jai'rus,

> > Thanks for all of the help everyone.  Still not sure how to make this
work
> > the way I'm expecting.

> > When I do this:
> >     return Error(L"Too many beeps");
> > in my code I do get an error back to my VB code but the description is
> still
> > "Method ~ of object ~ failed.  How can I make Err.Description in VB be =
> to
> > "Too many beeps"?

> How do you handle exception in VB?
> Below html sample, which uses beeper object and catches exception,
> on my PC it works fine.

> <html>

> <script language=jscript>
> function beepJava()
> {
>  try
>  {
>   beeperobj.beep();
>  } catch(e)
>  {
>   alert("Error, description="+e.description);
>  }
> }
> </script>

> <script language=vbscript>
>  sub beepVB
>   on error resume next
>   beeperobj.beep()
>   if err.number <> 0 then
>    msgbox "Error, description=" & err.description
>    err.clear
>   end if
>  end sub
> </script>

> <body>
>  <object classid="clsid:6384d586-0fdb-11cf-8700-00aa0053006d"
> id=beeperobj></object>
>  <input type=button value="Test Java Beep" onclick="beepJava();">
>  <input type=button value="Test VB Beep" onclick="beepVB();">
> </body>
> </html>

> --
> Best regards,
> Vadim Melnik,
> {*filter*} Consultant.
> _____________________________
> http://www.*-*-*.com/



Sun, 12 Oct 2003 17:58:24 GMT  
 
 [ 14 post ] 

 Relevant Pages 

1. Errors from C++ -> VB

2. Java->JNI->C++->vb.dll

3. C->->->->C++

4. Development C++ <> VB.NET

5. VB --> C++ equivalent

6. VB --> C++

7. VB --> C++ (array questions)

8. VB --> C++

9. VB forms -> Visual C++

10. Conversion Borland c++ ->>Visual c++!!

11. Why this bitwise error (>>>)

12. >>>Moving to C/C++

 

 
Powered by phpBB® Forum Software