471,337 Members | 841 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

DLL Hell - graceful handling/application termination

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
3 1640
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
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

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

Similar topics

3 posts views Thread by Jacob H | last post: by
reply views Thread by Alexander Staubo | last post: by
9 posts views Thread by Hans-Joachim Widmaier | last post: by
12 posts views Thread by Ritz, Bruno | last post: by
2 posts views Thread by Susan Baker | last post: by
13 posts views Thread by junw2000 | last post: by
35 posts views Thread by eliben | 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.