The trick here is to get a callback function to communicate
with LabVIEW. This is possible, but not necessarily easy. You will need
to write a DLL that has the callback function in it. The callback
function should fire an occurrence (or notifier, or queue). The VI,
meanwhile, must create the occurrence and call a function that
configures the service to use the callback function in your DLL. Then,
the VI must have a branch of the code that waits for the occurrence to
fire, after which it can do whatever is necessary to shutdown. Here's a
rough skeleton of the DLL code.
#inlude "extcode.h"
//forward declare
DWORD WINAPI MyHandler(
DWORD dwControl,
DWORD dwEventType,
LPVOID lpEventData,
LPVOID lpContext
);
//Called by the VI. Should pass in the handle from GenerateOccurrence
int ConfigureOnStop(Occurrence *o)
{
//Setup service callback function
RegisterServiceCtrlHandlerEx(name, MyHandler, o)
}
//The event handler
DWORD WINAPI MyHandler(
DWORD dwControl,
DWORD dwEventType,
LPVOID lpEventData,
LPVOID lpContext
)
{
Occurrence *o=(Occurrence*)lpContext;
if(dwControl==SERVICE_CONTROL_STOP)
{
//fire the occurrence
Occur(*o);
}
}
What I'm not too sure about is how all of this will interact with the
srvany executable, which presumably installs it's own service handler
function. My guess is that you will replace that function with your
own. As long as srvany didn't have anything important left to do, that
shouldn't be a problem. If it did... well, more work may need to be
done.