0

我正在为 IDC 服务提供商编写一个测试 DLL。我还编写了一个加载 XFS 管理器的 mfc 测试应用程序。

我在调用函数 WFSOpen 时遇到了一些问题。管理器正确加载 SPI dll 并调用其 WFPOpen 函数。WFPOpen 正确执行,到达 return 语句并将 WFS_SUCCESS 返回给调用者。然后在 XFS 管理器 dll 中发生了一些不好的事情,抛出了一个异常,并且 WFSOpen 函数将 WFS_ERR_INTERNAL_ERROR 返回给我的测试应用程序。

我总是收到这样的信息:

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

XFS 日志文件报告了这一点:

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

我在 Windows 8.1 64bit 中使用 Visual Studio 2012

4

1 回答 1

0

我设法以这种方式解决了异常:

#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);
};

使用 WINAPI 导出 WFPxxx 函数时,生成的 dll 具有 _WFPxxx@yyy 名称,msxfs.dll 无法读取该名称,从而导致错误 WFS_ERR_INVALID_SERVPROV。

解决方案是使用 msxfs.dll 指定可识别的名称

#pragma comment(linker, "/EXPORT:WFPxxx=_WFPxxx@yyy")
于 2015-07-02T10:03:10.977 回答