So, I have a C ++ dll that I use in my C # application to monitor Windows messages. I want to know if WM_CLOSE and WM_QUERYENDSESSION are sent because I do not see this from a C # application. If I receive one of these messages, I want to do some cleaning with my files, but the problem is that I kill it with TM, the functions do not work. It is stitches that I do not receive messages. I think the problem is that the task manager sends the message to the C # application, and not to the C ++ dll.
The code:
C ++:
typedef void (*CLOSING_FUNCTION)();
CLOSING_FUNCTION myClosingFunction;
typedef void (*SHUTDOWN_FUNCTION)();
SHUTDOWN_FUNCTION myShutdownFunction;
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_CREATE:
return 0;
case WM_CLOSE:
myClosingFunction();
return 0;
case WM_QUERYENDSESSION:
myShutdownFunction();
return 1;
case WM_DESTROY:
myClosingFunction();
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
WITH#:
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void Close_Function();
private static Close_Function myCloseDelegate;
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void Shutdown_Function();
private static Shutdown_Function myShutdownDelegate;
static void StartMonotoring()
{
myCloseDelegate = Close;
myShutdownDelegate = Shutdown;
InterceptMessages(myCloseDelegate, myShutdownDelegate);
}
static void Close();
static void Shutdown();
source
share