0

I am writing an Win32 C++ service for interfacing an bio-metric device. The SDK provided by the manufacturer uses MFC. I have no experience or knowledge regarding MFC.

Platform : Windows 10

Architecture : x64

Toolchain : MSVC 2017

DWORD SGFPM_EnableAutoOnEvent (HSGFPM hFpm, BOOL enable, HWND hwnd, void* reserved)

Parameters

pFPM

The handle of the SGFPM object

enable

TRUE: enables Auto-On

FALSE: disables Auto-On

hwnd

Window handle to receive Auto-On message

reserved Not used

The third parameter requires Window handle to receive Auto-On message. The sample application is an MFC based GUI application and not a service.

My question is what should be the value for third parameter. In Linux we fill a NULL value but I don't know what should I enter in my case.

Dark Sorrow
  • 1,681
  • 14
  • 37
  • You fill it in with the `hwnd` (think of it as an identifier for the operating system) of the window you want to receive your message in. How do you find that value? No idea.. if it's another application you might use [FindWindow](https://learn.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-findwindowa) or if it's part of the same project you could use MFC's provided [GetSafeHwnd](https://msdn.microsoft.com/en-us/vstudio/d64ehwhz(v=vs.94)) with the MFC-managed window – Marco A. Oct 12 '18 at 10:24
  • @MarcoA., both function say window handle, will it work with a service? Find Window requires window name and as my program is an service it won't have an window name. Also GetSafeHwnd is an member of CWnd class which is used for GUI and my application is an Win32 Service developed in C++. – Dark Sorrow Oct 12 '18 at 10:31
  • Usually services don't have windows. You can try to pass NULL, in that case how the parameter is handled is up to the implementation. – Marco A. Oct 12 '18 at 10:40
  • 3
    If your required to have an HWND then Windows supports the idea of a "Message only Window" that you can create to sink messages, see https://stackoverflow.com/questions/4081334/using-createwindowex-to-make-a-message-only-window – Alex K. Oct 12 '18 at 10:45
  • @MarcoA., Using NULL does not detect event. – Dark Sorrow Oct 12 '18 at 11:03
  • @AlexK., I will give a try to Message Only Window – Dark Sorrow Oct 12 '18 at 11:03
  • Do note that services run in their own session, and window messages can't pass across session boundaries. So using a window of any kind to receive messages will only work if the SDK is running in, and generating the messages in, the service's own session. – Remy Lebeau Oct 12 '18 at 15:41

1 Answers1

1

You have to create a window to receive the event from the funtion SGFPM_EnableAutoOnEvent, they are probably using the function SendMessage or PostMessage, anyway you are creating a windows service and they have not UI, the services runs on the winstation0 and the UI is not available for logged users, your window will be hidden anyway.

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
        switch (message)
    {
    case WM_APP_SGAUTOONEVENT:
        WORD isFinger= wParam;
        SGDeviceInfoParam device_info;
                memcpy(&device_info, (SGDeviceInfoParam*)lParam,sizeof(device_info));
                //Add your code here...
                return 1;
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}
HWND CreateMyWindow(){
    static const char* class_name = "DUMMY_CLASS";
    WNDCLASSEX wx = {};
    wx.cbSize = sizeof(WNDCLASSEX);
    wx.lpfnWndProc = WndProc;        // function which will handle messages
    wx.hInstance = current_instance;
    wx.lpszClassName = class_name;
    if ( RegisterClassEx(&wx) ) {
      return CreateWindowEx( 0, class_name, "dummy_name", 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, NULL, NULL );
    }
    return NULL;
}

then with the result of the CreateMyWindow funtion you can pass that parameter in the call to SGFPM_EnableAutoOnEvent