尝试使用此功能时出现此错误
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 );
答案 0 :(得分:3)
此运行时检查可防止函数声明与实际定义不匹配。将代码编译到静态库或DLL时可能发生的事故。常见的不匹配是调用约定或传递的参数的数量或类型。
鞋适合,你有一个名为WSPAPI的宏,它声明了调用约定。它通常扩展为__cdecl或__stdcall,通常偏向__stdcall。因此,这个宏在客户端代码中具有错误值的可能性非常高。如果您无法弄清楚如何正确设置此宏,请向图书馆作者寻求帮助。
编辑后:使用其他故障模式,您正在加载错误版本的DLL。并且您的LPFN_GETLSPGUID函数指针声明错误,缺少WSPAPI宏。我会把钱放在那个,特别是因为我看不到它。
评论之后,信息正在慢慢渗透:
它定义为typedef void(* LPFN_GETLSPGUID)(GUID * lpGuid);
哪个错了,应该是
typedef void (WSPAPI * LPFN_GETLSPGUID)(GUID *lpGuid);
如果您没有可用的宏,则不太可能,请用__stdcall代替WSPAPI。