For Programmers: Free Programming Magazines  


Home > Archive > Visual Studio > May 2006 > DLL function to set Error object?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author DLL function to set Error object?
Maximus

2006-05-17, 7:05 pm

I need to write a plain Windows DLL to feed a VB application. How to write
code to report an error which can reflect on VB's Err object? I searched the
Internet and could not locate an answer...


Karl E. Peterson

2006-05-17, 7:05 pm

Maximus wrote:
> I need to write a plain Windows DLL to feed a VB application. How to
> write code to report an error which can reflect on VB's Err object? I
> searched the Internet and could not locate an answer...


You can't, afaik. (Given your cross-post, I suppose it's appropriate to
confirm you are referring to Classic VB, right?) Why would you want to do
that? Most "standard" DLLs return an error code, as appropriate. Most VB
users are accustomed to this behavior.
--
Working without a .NET?
http://classicvb.org/


Tony Proctor

2006-05-18, 4:04 am

Plain Windows DLLs normally return error codes to their callers. Only a COM
DLL can actually raise an exception and have it affect the caller's Err
object

Tony Proctor

"Maximus" <maximus@microsoft.com> wrote in message
news:O0KlyzfeGHA.1208@TK2MSFTNGP02.phx.gbl...
> I need to write a plain Windows DLL to feed a VB application. How to write
> code to report an error which can reflect on VB's Err object? I searched

the
> Internet and could not locate an answer...
>
>



Ulrich Korndoerfer

2006-05-18, 7:08 pm

Hi,

Maximus schrieb:
> I need to write a plain Windows DLL to feed a VB application. How to write
> code to report an error which can reflect on VB's Err object? I searched the
> Internet and could not locate an answer...


If a method or function of your Dll shall return an error trappable by
VBs error handling, you have to return a HRESULT. For a method this has
to be converted to a function returning a HRESULT. For a function the
function too has to return a HRESULT. To return the functions "real"
return value you have to use a hidden parameter as last parameter in the
functions parameter list.

To make those methods and functions error handling then available to VB
you have to access them in VB by using a typelibrary. Typelibraries are
written using IDL and compiled using the MIDL compiler. For each method
and function an appropriate typelib entry has to be written.

A simple method to obtain the correct IDL definitions, from which the
method and function signatures can be retrieved too is to write a dummy
VB COM dll. This dll should be made up of one class, which has all the
methods and functions you need declared (no implementation needed). Then
compile this VB dll and use OLEVIEW.exe to extract the typelib in IDL
text format. Then modify the typelibs ILD code to suit your needs and
recompile it using MIDL.

--
Ulrich Korndoerfer

VB tips, helpers, solutions -> http://www.proSource.de/Downloads/

-----------------------------------------------------------------------
Plea for a bright future for VB classic.
Sign the petition to Microsoft: -> http://classicvb.org/petition/
-----------------------------------------------------------------------
Ralph

2006-05-18, 10:01 pm


"Maximus" <maximus@microsoft.com> wrote in message
news:O0KlyzfeGHA.1208@TK2MSFTNGP02.phx.gbl...
> I need to write a plain Windows DLL to feed a VB application. How to write
> code to report an error which can reflect on VB's Err object? I searched

the
> Internet and could not locate an answer...
>
>


Are you writing your "plain Windows Dll" in C/C++?

If so, to supplement Ulrich's comment, look up the following article in the
MSDN Help CD...
"HOWTO: Raise an Error in Visual Basic From Your C DLL ID: Q189134"

-ralph



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com