运行一个function时运行时检查失败#0

尝试使用此function时出现此错误

void WSPAPI GetLspGuid( LPGUID lpGuid ) { memcpy( lpGuid, &gProviderGuid, sizeof( GUID ) ); } 

错误

 Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention. 

该函数是通过使用调用的

 HMODULE hMod = NULL; LPFN_GETLSPGUID fnGetLspGuid = NULL; int retval = SOCKET_ERROR; // Load teh library hMod = LoadLibraryA( LspPath ); if ( NULL == hMod ) { fprintf( stderr, "RetrieveLspGuid: LoadLibraryA failed: %d\n", GetLastError() ); goto cleanup; } // Get a pointer to the LSPs GetLspGuid function fnGetLspGuid = (LPFN_GETLSPGUID) GetProcAddress( hMod, "GetLspGuid" ); if ( NULL == fnGetLspGuid ) { fprintf( stderr, "RetrieveLspGuid: GetProcAddress failed: %d\n", GetLastError() ); goto cleanup; } // Retrieve the LSPs GUID fnGetLspGuid( Guid ); 

此运行时检查可防止函数声明与实际定义之间的不匹配。 将代码编译到静态库或DLL时可能发生的事故。 常见的不匹配是调用约定或传递的参数的数量或类型。

鞋适合,你有一个名为WSPAPI的宏声明了调用约定。 它通常扩展到__cdecl或__stdcall,通常偏向__stdcall。 所以这个宏在你的客户端代码中有错误的价值。 如果您无法弄清楚如何正确设置这个宏,请向图书馆作者寻求帮助。


编辑之后:使用额外的失败模式,您正在加载DLL的错误版本。 而你的LPFN_GETLSPGUID函数指针声明是错误的,缺少WSPAPI宏。 我会把钱放在那个上面,特别是因为我看不见它。


经过评论,信息正在慢慢流淌:

它被定义为typedef void(* LPFN_GETLSPGUID)(GUID * lpGuid);

这是错的,应该是

 typedef void (WSPAPI * LPFN_GETLSPGUID)(GUID *lpGuid); 

如果您没有可用的宏,则用__stdcall替换WSPAPI。