运行函数时检查失败#0
Run-Time Check Failure #0 when running a 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: %dn", 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: %dn", GetLastError() );
goto cleanup;
}
// Retrieve the LSPs GUID
fnGetLspGuid( Guid );
此运行时检查防止函数声明与实际定义之间的不匹配。将代码编译成静态库或DLL时可能发生的意外。常见的不匹配是调用约定或传递的参数的数量或类型。
非常合适,您有一个名为WSPAPI的宏来声明调用约定。它通常展开为__cdecl或__stdcall,通常偏向于__stdcall。所以很有可能这个宏在客户端代码中有错误的值。如果您不知道如何正确设置该宏,请向库作者寻求帮助。
编辑后:附加的失败模式,你正在加载错误版本的DLL。并且LPFN_GETLSPGUID函数指针声明是错误的,缺少WSPAPI宏。我把钱压在那上面,尤其是因为我看不见它。
注释后,信息慢慢流入:
定义为typepedef void (*LPFN_GETLSPGUID) (GUID *lpGuid);
错了,应该是
typedef void (WSPAPI * LPFN_GETLSPGUID)(GUID *lpGuid);
如果没有可用的宏(不太可能),则用__stdcall代替WSPAPI。
相关文章:
- libprotobuf 检查在 Mac OS 上执行程序时失败
- 运行时检查失败 #2 变量"A"周围的堆栈已损坏
- 运行时检查失败 #0 用于运行时重新编译
- 运行时检查失败 #2 - 变量"e"周围的堆栈已损坏。发生
- 运行时检查失败 #2 MSVC 仅使用 utf8proc 进行调试
- std::copy 导致运行时检查失败 #2
- 运行时检查失败 #2 - 变量周围的堆栈'...'已损坏
- 运行时检查失败 #2 - 变量"l1"周围的堆栈已损坏
- C ++回测问题:如何检查构造函数在假定失败时是否失败(给定输入的无效参数)
- C++:此代码可以编译,但引发运行时检查失败 #2 - 围绕变量周围的堆栈'num'已损坏。发生
- 运行时检查失败 - 变量周围的堆栈已损坏
- 类型检查的编译时失败
- 调试:运行时检查失败 #2 - 变量"LoggerThread"周围的堆栈已损坏
- 运行时检查失败 #2 - 变量周围的堆栈'k'已损坏
- 建筑物提升失败检查子模块/上下文
- 运行时检查失败 #2 - 变量"数字选择"周围的堆栈已损坏
- GDB在断点检查条件时失败
- 写一个概念检查库,但在所有筹款算术类型上都失败了
- 检查日志文件以找出 vcredist.exe 安装失败的原因
- 检查 istream::read 和 istream::seekg 失败的最佳方法