How exceptions work when using DLLImport

I am using DLLImport to call the GhostScript library from a C # application.

So I have code like this

[DllImport("gsdll32.dll", EntryPoint = "gsapi_init_with_args")] private static extern int gsapi_init_with_args(IntPtr instance, int argc, IntPtr argv); try { intReturn = gsapi_init_with_args(intGSInstanceHandle, intElementCount, intptrArgs); } catch (Exception ex) { throw new ApplicationException(ex.Message, ex); } 

I'm going to see the source code for GhostScript that is written in C or C ++, but overall I was wondering what would happen if the GhostScript code threw an unhandled exception? Would it be a catch caught there, or would it look like this:

 catch { // blah } 
+6
source share
1 answer

It will not throw an exception, you should look at return codes. http://pages.cs.wisc.edu/~ghost/doc/AFPL/7.04/API.htm#return_codes

A fairly standard C programming method, a non-zero return code for an error, sometimes followed by a second API call to get more detailed information about the error.

+2
source

Source: https://habr.com/ru/post/913479/


All Articles