471,327 Members | 2,682 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,327 software developers and data experts.

Raise Error to VB application

I havean app written in vb6 that links to a vb6 DLL file. The app handles
errors raised by the DLL based on the error number (Err.Number). I would
now like to convert the DLL to c#. How can I raise errors from the c# DLL
so that the VB6 exe can diferentiate between them (eg using the old
Err.Number system)?

Thanks

Alan
Dec 19 '05 #1
3 2282
Alan,

What you want to do in this situation is create your own class derived
from Exception. Once you do that, you can set the HResult property to the
value that corresponds to the number returned from Err.Number.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Alan Roberts" <al**@statistixl.co.uk> wrote in message
news:u1**************@TK2MSFTNGP09.phx.gbl...
I havean app written in vb6 that links to a vb6 DLL file. The app handles
errors raised by the DLL based on the error number (Err.Number). I would
now like to convert the DLL to c#. How can I raise errors from the c# DLL
so that the VB6 exe can diferentiate between them (eg using the old
Err.Number system)?

Thanks

Alan

Dec 19 '05 #2
Alan,
How can I raise errors from the c# DLL
so that the VB6 exe can diferentiate between them (eg using the old
Err.Number system)?


throw Marshal.GetExceptionForHR(yourErrorCode);

where yourErrorCode is a HRESULT error code. Some HRESULTs will be
mapped to built-in VB error numbers and others are used as is.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Dec 19 '05 #3
Thanks guys, I will have a play with these.

Alan

"Alan Roberts" <al**@statistixl.co.uk> wrote in message
news:u1**************@TK2MSFTNGP09.phx.gbl...
I havean app written in vb6 that links to a vb6 DLL file. The app handles
errors raised by the DLL based on the error number (Err.Number). I would
now like to convert the DLL to c#. How can I raise errors from the c# DLL
so that the VB6 exe can diferentiate between them (eg using the old
Err.Number system)?

Thanks

Alan

Dec 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by James Stroud | last post: by
2 posts views Thread by Bogdan Zamfir | last post: by
2 posts views Thread by Mortimer Schnurd | last post: by
7 posts views Thread by Steven W. Orr | last post: by
4 posts views Thread by Diego F. | last post: by
reply views Thread by rosydwin | last post: by

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.