How to determine process exit from DLL in C #

I have a WPF application that calls functions inside a native DLL (written in C ++). This feature in .DLL sometimes does a Process Exit, which kills a WPF application.

Example:

WPF App: ..... [DllImport("native.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)] private static extern void NativeMethod(); ..... void CallFunction() { //Call the native function NativeMethod(); } .... 

There is a way out inside NativeMethod, and I cannot change the source code of the .dll. Does anyone know a way to capture this output in a DLL from .NET code?

Thanks in advance,

+4
source share
2 answers

AppDomain.ProcessExitOk, the problem with using AppDomain was that they only work with .NET assemblies :( Therefore, I had to create an assembly that loads my own DLL through P / Invoke. After that, I could load the assembly into another AppDomin and call functions of the embedded DLL file .dll. I am capturing the AppDomain.ProcessExit event from AppDomain and I could capture the output;).

Thanks aiampogi for the idea;)

+3
source

At the top of my head, the only thing I can think of is to load the DLL into the process / application domain (more on appdomain), then call this method and register the ProcessExit event to handle it properly.

I can try to do this later, but I'm just not sure that you can call static methods in appdomain or call a method of a non-serialized class in appdomain.

+1
source

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


All Articles