0
votes

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.

1
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 or if it's part of the same project you could use MFC's provided GetSafeHwnd with the MFC-managed windowMarco A.
@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
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.
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 stackoverflow.com/questions/4081334/…Alex K.
@MarcoA., Using NULL does not detect event.Dark Sorrow

1 Answers

1
votes

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