By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,694 Members | 1,882 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,694 IT Pros & Developers. It's quick & easy.

DLL Hell - graceful handling/application termination

P: n/a
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.

Dec 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
I believe you should be able to "catch" exceptions and "handle" them. How
this is done will depend on the language the unmanaged dll is written with.
With C++
try
{
...All code....
}
catch(void*)
{
...handle it
}
should catch just about any exception missed by other more specific
try-catch blocks..

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

Dec 20 '05 #2

P: n/a
Hi Susan,

This has nothing to do with C# or .NET, but OK, here goes.

the usual C++ try...catch will not work for SEGVs, as far as I remember.
What you need is what is known as structured exception handling (SEH).
Please refer to Visual C++ documentation on the __try and __catch statements
(the underscores are not a typo!).

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]
"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.


Dec 20 '05 #3

P: n/a

"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.
Dec 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.