"Susan Baker" <sb****@no.spam.net> wrote in message
news:do*********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com...
Hi,
I am writing a (unmanaged) Win32 DLL. I want to be able to handle any
SEGVs (segmentation violations) gracefully, by using an error handler of
sorts.
Currently, if a user of my DLL (typically a VB programmer) passes a null
(or invalid) pointer to my library - the entire application crashes,
leaving shared memory, database connections etc in a "dirty" state. I
would like a way of gracefully handling user "actions" like this - without
crashing spectacularly.
Any help much appreciated.
If the application crashes, it's because you are using the arguments passed
on a public interface"as is" without validating, this is bad, you as the
'callee' are responsible for the validation of your preconditions.
If your interface is COM based, you have to validate the arguments and
return an E_INVALID_ARG HRESULT when validation fails, additionally you can
return some extended error info. If your interface is a simple "C" export,
you can apply the same HRESULT return based protocol.
Note that I don't see how a VB programmer can pass invalid pointers other
than "null", VB doesn't know anything about pointers.
Willy.