I have a C# console application where I'm using CEN XFS(Extensions for Financial Services) specification to get ATM information. I'm using PInvoke to communicate with msxfs.dll. I'm registering to listen for SERVICE_EVENTS, USER_EVENTS, SYSTEM_EVENTS, EXECUTE_EVENTS invoking method
HRESULT WFSRegister(hService, dwEventClass, hWndReg)
In my code I create an instance of WNDCLASSEX assign a method that will process Windows Messages to its lpfnWndProc field; then I register a class using RegisterClassEx([In] ref WNDCLASSEX lpWndClass) and create a Window calling CreateWindowEx.
In my code later I execute WFS_CMD_CDM_SET_CASH_UNIT_INFO command and it returns WFS_SUCCESS, base on the documentation this command will generate WFS_SRVE_CDM_CASHUNITINFOCHANGED service event but I'm not getting any window message with value 304 (#define WFS_SRVE_CDM_CASHUNITINFOCHANGED (CDM_SERVICE_OFFSET + 4)) or any message related with XFS Events.
It is possible that the msxfs.dll or Service Providers I'm using does not have events notification implemented. Am I missing something that prevents me to get windows messages?
In order to receive window messages you must have a separate thread which is running the equivalent of the standard Windows message pump:
Furthermore, it is not necessary to do all this via P/Invoke — you can do it in C# natively by creating a hidden form and overriding
WndProc. You still have to create and run that form on a separate thread, and to useInvokewhen you need to close it.Note that for the form to be fully hidden in addition to setting the
FormBorderStyletoNone,ShowIcontofalse,ShownInTaskbarto false,Visibletofalse, andWindowStatetoMinimized, you should also change the Extended Window Styles to includeWS_EX_TOOLWINDOWduring form creation:Finally, note that the
WFSRESULTpointer which you get vialParaminWndProcwhen you receive an event needs to be freed usingWFSFreeResult(). Inspecting theBuffermember of theWFSRESULTstructure and marshaling any nested structures returned in it needs to be completed before callingWFSFreeResult()or the data will be invalid.