Raise Error to VB application

A

Alan Roberts

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
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
M

Mattias Sjögren

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
 

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