473,394 Members | 1,840 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 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 1705
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jacob H | last post by:
Hello all, I'm nearing the completion of my first graphical console game and my thoughts have turned to the subject of gracefully handling runtime errors. During development I like to not handle...
0
by: Alexander Staubo | last post by:
Python does not seem to clean up gracefully on SIGTERM: The exit sequence is not invoked on termination, so the atexit module cannot be used to install shutdown logic. Further, while the signal...
9
by: Hans-Joachim Widmaier | last post by:
Hi all. Handling files is an extremely frequent task in programming, so most programming languages have an abstraction of the basic files offered by the underlying operating system. This is...
12
by: Ritz, Bruno | last post by:
hi in java i found that when a method has a throws clause in the definition, callers must either handle the exceptions thrown by the method they are calling or "forward" the exception to the...
2
by: Susan Baker | last post by:
Hi, I am writing a 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...
10
by: Anthony England | last post by:
(sorry for the likely repost, but it is still not showing on my news server and after that much typing, I don't want to lose it) I am considering general error handling routines and have...
13
by: junw2000 | last post by:
Is C++ Exception handling useful? think it is too complicated. What kinds of project need to use it? Thanks.
94
by: Chad | last post by:
On to top of page 163 in the book "The C Programming Langauge" by K & R, they have the following: char *strdup(char *s) { char *p; p=(char *)malloc(strlen(s)+1); if( p != NULL) strcpy(p,s):...
35
by: eliben | last post by:
Python provides a quite good and feature-complete exception handling mechanism for its programmers. This is good. But exceptions, like any complex construct, are difficult to use correctly,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.