tags:

views:

46

answers:

1

Hey,

I'm using C# to consume a C library using the following syntax:

[DllImport("clib.so") static extern int func(char* foo);

I'd like to know if there's any way to catch an exit(#) that happens in the C code so I can reload the library if a critical error ever happens.

Thanks!

+2  A: 

I believe exit() will terminate the process without ever re-entering managed code. Possibly you could register a function to notify you when this happens using a prior call to atexit() via P/Invoke. But the process will still exit if you return from this. I imagine not returning will leave the process in an indeterminate state. You may need to implement some form of process isolation and watch for process exit of your moribund library.

http://msdn.microsoft.com/en-us/library/6wdz5232.aspx

Steve Townsend
+1 for "moribund" and a reasonable solution
StingyJack