- Home /
Question by
$$anonymous$$ · Dec 16, 2011 at 09:01 PM ·
serviceexitbatchmode
Unity and WM_QUIT
Hi,
I'm using XYNTService to run one of my application as a windows service.
It works just fine when I launch the service, as my application starts running in background.
When I stop the service, XYNTService send a message WM_QUIT. However, Unity doesn't react to it.
Comment
Best Answer
Answer by $$anonymous$$ · Mar 26, 2012 at 03:33 PM
I found this workaround :
private const UInt32 WM_QUIT = 0x0012;
const Int32 PM_REMOVE = 1;
struct POINTAPI {
public Int32 x;
public Int32 y;
}
struct MSG {
public Int32 hwnd;
public Int32 message;
public Int32 wParam;
public Int32 lParam;
public Int32 time;
public POINTAPI pt;
}
[DllImport( "user32.dll", SetLastError = true )]
private static extern bool PeekMessage(ref MSG lpMsg,
Int32 hwnd,
Int32 wMsgFilterMin,
Int32 wMsgFilterMax,
Int32 wRemoveMsg);
void Update() {
MSG msg = new MSG();
if ( PeekMessage( ref msg, 0, 0, 0, PM_REMOVE ) ) {
if ( msg.message == WM_QUIT ) {
Debug.Log("Message : " + msg.message);
Application.Quit();
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613062131im_/https://answers.unity.com/themes/thub/images/avi.jpg)