473,804 Members | 2,195 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error handling for unmanaged code

I've got a call within my .NET code to a function which uses an API call to
get printer settings. When there's an error in the API call code, it
crashes the .NET app. Try Catch doesn't prevent the crash - it's like it
crashes before the catch catches.....

Any ideas how to error handle this type of function so it doesn't crash the
application??

TIA

Harry
Nov 20 '05 #1
2 2017
In article <OA************ **@TK2MSFTNGP10 .phx.gbl>, Harry Simpson wrote:
I've got a call within my .NET code to a function which uses an API call to
get printer settings. When there's an error in the API call code, it
crashes the .NET app. Try Catch doesn't prevent the crash - it's like it
crashes before the catch catches.....

Any ideas how to error handle this type of function so it doesn't crash the
application??

TIA

Harry


Examples? If the unmanaged code does something stupid that cause's the
application to crash - there isn't much you'll be able to do about it.
That's why it's called unmanaged code - the runtime has no control over
what it can/can't do.

--
Tom Shelton [MVP]
Nov 20 '05 #2
That's what i thought. Even spinning of the DLL call into another thread
will still crash the code right?

Threads won't/can't isolate the main managed code app from the unmanaged
code - Am i correct?

I'm trying to get printer status with winspool.drv.
Can winspool.drv be interopted for a Windows Forms application.

The WMI is not bringing back accurate info on status so....

I've got API declares but the API call is very unstable and crashes and
brings down the call app. Try catches just don't work.

Help!

Harry

"Tom Shelton" <to*@YOUKNOWTHE DRILLmtogden.co m> wrote in message
news:Oc******** *****@TK2MSFTNG P12.phx.gbl...
In article <OA************ **@TK2MSFTNGP10 .phx.gbl>, Harry Simpson wrote:
I've got a call within my .NET code to a function which uses an API call to get printer settings. When there's an error in the API call code, it
crashes the .NET app. Try Catch doesn't prevent the crash - it's like it crashes before the catch catches.....

Any ideas how to error handle this type of function so it doesn't crash the application??

TIA

Harry


Examples? If the unmanaged code does something stupid that cause's the
application to crash - there isn't much you'll be able to do about it.
That's why it's called unmanaged code - the runtime has no control over
what it can/can't do.

--
Tom Shelton [MVP]

Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
4491
by: Thelma Lubkin | last post by:
I use code extensively; I probably overuse it. But I've been using error trapping very sparingly, and now I've been trapped by that. A form that works for me on the system I'm using, apparently runs into problems on the system where it will actually be used, and since I used so little error-trapping it dies very ungracefully. I will of course try to fix whatever is causing the error and add error-trapping to the functions where the...
0
2065
by: Joe | last post by:
Reposting here as there were no useful replies in the dotnet.framework NG... What is the correct pattern for handling exceptions in IDisposable.Dispose, especially in a class that manages multiple unmanaged resources? An example of such a class is System.ComponentModel.Container. I have always understood that the IDisposable contract was that Dispose guarantees to release unmanaged resources owned by the object - even if the Dispose...
12
6194
by: Sharon | last post by:
I’m wrote a small DLL that used the FreeImage.DLL (that can be found at http://www.codeproject.com/bitmap/graphicsuite.asp). I also wrote a small console application in C++ (unmanaged) that uses the DLL above. Now the application, together with the above DLL’s is successfully loading a TIF image file (62992 x 113386 Pixels, Huffman RLE compression, 3200 x 3200 DPI resolution, binary colored (1 Bit Per Pixel), file on disk size 43.08...
6
3134
by: Ken | last post by:
When running a program in the debugger, what would cause it to crash without any error messages? I get "The program has exited with code 0 (0x0)". The program is a MDI app with threading for several serial ports. It only crashes when data is being received on one or more of the serial ports. Could someone please give me some ideas about what would cause a program to terminate in this way? Thanks....
9
2232
by: Gustaf | last post by:
I'm confused about structured error handling. The following piece of code is a simplification of a class library I'm working on. It works, and it does what I want, but I'm still not convinced that I have been doing it right. I think I overdo it. Please have a look: -- using System; using System.IO;
0
929
by: mhdostal | last post by:
I have a multi-threaded application using both managed (C#/.NET) and unmanaged code (C++). The unmanaged code calls into the manage code (via COM Interop) to perform a variety of tasks. Every two or three days the application would unexpectedly crash; I added a GC.Collect() call to the end of every method in the module in question and now the problem happens 4 -5 time a day. Some debug information from WinDbg is below. I'm currently...
11
7036
by: Don | last post by:
When using Visual Basic .NET with a reference to Interop.Outlook, is there a way to get more detailed information about an error other than Exception.Message or Exception.ToString? For example, Outlook's MailItem.SaveAs method can return an error message of "The operation failed", but I have no idea what that means. As a test, I tried SaveAs using a filename that contained illegal characters and got the error message "Internal Application...
0
11604
by: Lysander | last post by:
Thought I would give something back with a few articles. This article is a bit of code to add error handling. When I have time, I want to write articles on multilingual databases, and Access Security, but I'll start with something short and simple This code was written in Access 2003 but should be valid in Access 2000 By default, when you start a new module, either in a form or report, or a global module, Access does not declare Option...
9
3301
by: MrDeej | last post by:
Hello guys! We have an SQL server which sometimes makes timeouts and connection errors. And we have an function witch writes and updates data in 2 tables on this server. When the SQL server error appears it, in 99%, of the cases, works if we just press the play button in VBA debug. Therefor we have maked an error handling which just tryes again. However, as this error handling is difficult to test because of maybe 1 or 2 errors a day, we...
0
9715
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9595
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10354
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10097
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7642
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6867
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4313
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3835
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.