VB6 client needs "Err.Raise" from C#

M

Mortimer Schnurd

Hi,
I've been dabbling with C# for a short time now but am ready to use it
in extending/converting older VB6 applications. I have one VB6
application I am now working to extend and I would like to write the
addition in C#. I've scoured the Internet for the procedures
necessary to use this type of interoperability and feel comfortable
with those so far (strong name, GAC, attributes, etc).

My question: How does my C# component notify my VB6 application when
it encounters an error? In VB6 you just used the Raise method of the
Err object and an "On Error" in the client would get processed. Can I
somehow "raise an error" which will trigger the "On Error" in my VB6
application?

Thanks in advance for any guidance and heaps of thanks for any code
example!
--
Regards,
John Wood a.k.a Mortimer Schnurd
(e-mail address removed)

(to reply: remove "dropthistag")
 
N

Nicholas Paldino [.NET/C# MVP]

Mortimer,

What you would do is raise an exception. When an exception is thrown,
it will convert it to an HRESULT, which is what will cause an error to be
raised in VB6. I believe you can specify the result you want to raise
yourself by throwing a ComException (where you can specify the HRESULT).

Hope this helps.
 
M

Mortimer Schnurd

Mortimer,

What you would do is raise an exception. When an exception is thrown,
it will convert it to an HRESULT, which is what will cause an error to be
raised in VB6. I believe you can specify the result you want to raise
yourself by throwing a ComException (where you can specify the HRESULT).

Hope this helps.

Thanks to your mention of HRESULT, I was able to locate an interesting
article on MSDN which explains the process.
http://tinyurl.com/5j7lm

I'll be trying it out first thing in the morning.

Thanks for your help Nicholas.
--
Regards,
John Wood a.k.a Mortimer Schnurd
(e-mail address removed)

(to reply: remove "dropthistag")
 
M

Mortimer Schnurd

Mortimer,

What you would do is raise an exception. When an exception is thrown,
it will convert it to an HRESULT, which is what will cause an error to be
raised in VB6. I believe you can specify the result you want to raise
yourself by throwing a ComException (where you can specify the HRESULT).

Hope this helps.

Nicholas,
I was finally able to prove to myself that VB6's On Error would trip
if an error was encountered in a .Net component. This is fantastic! I
did not have to do anything special in either VB6 or .Net other then
to set up .Net for normal interoperability. I did not have to specify
an Hresult. In fact, the MSDN ComException overview recommends NOT
using it but instead using the .Net exception. This is mostly to
accommodate using the component with other managed code projects.

Thanks again for your response.
--
Regards,
John Wood a.k.a Mortimer Schnurd
(e-mail address removed)

(to reply: remove "dropthistag")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top