Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / December 2005

Tip: Looking for answers? Try searching our database.

DLL Hell - graceful handling/application termination

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Susan Baker - 20 Dec 2005 02:51 GMT
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.
David - 20 Dec 2005 03:09 GMT
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..

> Hi,
>
[quoted text clipped - 9 lines]
>
> Any help much appreciated.
Dmytro Lapshyn [MVP] - 20 Dec 2005 07:27 GMT
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!).

Signature

Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]

> Hi,
>
[quoted text clipped - 9 lines]
>
> Any help much appreciated.
Willy Denoyette [MVP] - 20 Dec 2005 11:03 GMT
> Hi,
>
[quoted text clipped - 9 lines]
>
> 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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.