CEN XFS Exception when returning from WFPOpen

0

I'm writing a test DLL for an IDC service provider. I also written an mfc testing application that loads the XFS Manager.

I'm encountering some problems calling the function WFSOpen. The manager correctly loads the SPI dll and calls its WFPOpen function. The WFPOpen executes correctly, reaching the return statement and returning WFS_SUCCESS to the caller. Then in the XFS Manager dll something bad happens, an exception is thrown and the WFSOpen function returns WFS_ERR_INTERNAL_ERROR to my testing application.

I always get this message:

First-chance exception at 0x1000C285 (msxfs.dll) in TestXFSIDC.exe: 0xC0000005: Access violation writing location 0x011E3987.
(Date)01.07.2015 (Time)09:29.39,570
Exception occurred

The XFS log file reports this:

09:29:39.554 APICALL: WFSAsyncOpen
    actLogicalName: <MyCardReader>
    hApp: 398257252 0X17BCEC64
    actszAppId: <TestXFSIDC>
    actTraceLevel: 10 0X0000000A
    actTimeOut: 0 0X00000000
    actpHService: 8321216 0X007EF8C0
    actHWnd: 461622 0X00070B36
    dwSrvcVersionsRequired: 201731 0X00031403
    lpSrvcVersion: 8315892 0X007EE3F4
    lpSPIVersion: 8315364 0X007EE1E4
    actpRequestId: 8315352 0X007EE1D8

09:29:39.554 OpenKey( HKEY_CURRENT_USER,WOSA_CURRENT_USER_KEY_NAME,0,KEY_READ | KEY_WRITE,&hKeyWosaRoot) failed (reason=2,file=d:\buffington\development\cen xfs manager\source\xfs_conf.cpp,line=2168)

09:29:39.570 WFPCALL: WFPOpen
    tmpServiceHandle: 1 0X00000001
    actLogicalName: <MyCardReader>
    hApp: 398257252 0X17BCEC64
    actszAppId: <TestXFSIDC>
    actTraceLevel: 10 0X0000000A
    actTimeOut: 0 0X00000000
    actHWnd: 461622 0X00070B36
    tmpRqId: 1 0X00000001
    pUser->getServiceProviderHandle(): 1807786008 0X6BC0A018
    dwSPIVersionsRequired: 16908035 0X0101FF03
    lpSPIVersion: 8315364 0X007EE1E4
    dwSrvcVersionsRequired: 201731 0X00031403
    lpSrvcVersion: 8315892 0X007EE3F4

09:29:39.570 
(Date)01.07.2015 (Time)09:29.39,570
Called WFPOpen
09:29:39.570 
(Date)01.07.2015 (Time)09:29.39,570
Exiting WFPOpen
09:29:39.554 RegOpenKeyEx( x80000003, .DEFAULT\XFS )) failed (reason=5,file=d:\buffington\development\cen xfs manager\source\xfs_conf.cpp,line=384)
09:29:39.570 
(Date)01.07.2015 (Time)09:29.39,570
Exception occurred

I'm using Visual Studio 2012 in Windows 8.1 64bit

cen-xfs
asked on Stack Overflow Jul 1, 2015 by CPT-Sir

1 Answer

0

I've managed to solve the exception in this way:

#pragma comment(linker, "/EXPORT:WFPCancelAsyncRequest=_WFPCancelAsyncRequest@8")
#pragma comment(linker, "/EXPORT:WFPClose=_WFPClose@12")
#pragma comment(linker, "/EXPORT:WFPDeregister=_WFPDeregister@20")
#pragma comment(linker, "/EXPORT:WFPExecute=_WFPExecute@24")
#pragma comment(linker, "/EXPORT:WFPGetInfo=_WFPGetInfo@24")
#pragma comment(linker, "/EXPORT:WFPLock=_WFPLock@16")
#pragma comment(linker, "/EXPORT:WFPOpen=_WFPOpen@52")
#pragma comment(linker, "/EXPORT:WFPRegister=_WFPRegister@20")
#pragma comment(linker, "/EXPORT:WFPSetTraceLevel=_WFPSetTraceLevel@8")
#pragma comment(linker, "/EXPORT:WFPUnloadService=_WFPUnloadService@0")
#pragma comment(linker, "/EXPORT:WFPUnlock=_WFPUnlock@12")


extern "C"{
    DllExport HRESULT WINAPI WFPCancelAsyncRequest(HSERVICE hService, REQUESTID RequestID);
    DllExport HRESULT WINAPI WFPClose(HSERVICE hService, HWND hWnd, REQUESTID ReqID);
    DllExport HRESULT WINAPI WFPDeregister(HSERVICE hService, DWORD dwEventClass, HWND hWndReg, HWND hWnd, REQUESTID ReqID);
    DllExport HRESULT WINAPI WFPExecute(HSERVICE hService, DWORD dwCommand, LPVOID lpCmdData, DWORD dwTimeOut, HWND hWnd, REQUESTID ReqID);
    DllExport HRESULT WINAPI WFPGetInfo(HSERVICE hService, DWORD dwCategory, LPVOID lpQueryDetails, DWORD dwTimeOut, HWND hWnd, REQUESTID ReqID);
    DllExport HRESULT WINAPI WFPLock(HSERVICE hService, DWORD dwTimeOut, HWND hWnd, REQUESTID ReqID);
    DllExport HRESULT WINAPI WFPOpen(HSERVICE hService, LPSTR lpszLogicalName, HAPP hApp, LPSTR lpszAppID, DWORD dwTraceLevel, DWORD dwTimeOut, HWND hWnd, REQUESTID ReqID, HPROVIDER hProvider, DWORD dwSPIVersionsRequired, LPWFSVERSION lpSPIVersion, DWORD dwSrvcVersionsRequired, LPWFSVERSION lpSrvcVersion);
    DllExport HRESULT WINAPI WFPRegister(HSERVICE hService, DWORD dwEventClass, HWND hWndReg, HWND hWnd, REQUESTID ReqID);
    DllExport HRESULT WINAPI WFPSetTraceLevel(HSERVICE hService, DWORD dwTraceLevel);
    DllExport HRESULT WINAPI WFPUnloadService();
    DllExport HRESULT WINAPI WFPUnlock(HSERVICE hService, HWND hWnd, REQUESTID ReqID);
};

When exporting the WFPxxx function using WINAPI the dll produced has the _WFPxxx@yyy names, that are not readable by the msxfs.dll, which gives the error WFS_ERR_INVALID_SERVPROV.

The solution was to specify the name recognizable by the msxfs.dll using the

#pragma comment(linker, "/EXPORT:WFPxxx=_WFPxxx@yyy")
answered on Stack Overflow Jul 2, 2015 by CPT-Sir

User contributions licensed under CC BY-SA 3.0