使用 C++ 调用动态加载的 DLL 时发生访问冲突;
我有一个使用 VS2010 构建的 dll (C 代码)并定义了一组函数。我还有一个 exe(C++ 代码),使用 VS2010 构建,可以动态加载 dll 并调用函数。前几个函数调用工作正常,然后大约 20% 的时间调用第三个函数会导致地址 0 处的访问冲突。其余 80% 的时间通话都正常。导致问题的始终是同一个函数调用。
typedef void (__cdecl *mtSim_ResetODScan)(void);
mtSim_ResetODScan mpSim_ResetODScan;
if ((mpSim_ResetODScan = (mtSim_ResetODScan)GetProcAddress(mhSimDLL,
"_Sim_ResetODScan")) == NULL) return 0;
此时mpSim_ResetODScan = 0x5E9741D0。稍后调用该函数,当我调试可执行文件时,它会在函数调用处中断执行:
mpSim_ResetODScan();
尝试进入该函数会重新生成访问冲突。 VS 调试器报告 mpSim_ResetODScan 的值仍然是 0x5E9741D0。
注释掉 dll 中函数内的所有代码没有什么区别。
在 DLL 中:
extern "C" __declspec(dllexport) void __cdecl _Sim_ResetODScan(void);
Dependency Walker 显示 dll 和 exe 使用的是 MSVCR100.DLL 版本 10.0.30319.460。
关于如何进一步调试这个问题的任何建议,或者关于我可能错过的事情的任何提示?
I have a dll (C code) that is built using VS2010 and defines a set of functions. I also have an exe (C++ code), built using VS2010 that dynamically loads the dll and calls the functions. The first couple of function calls work fine then about 20% of the time a call to a third function causes an access violation at address zero. The other 80% of the time the call is fine. It's always the same function call that is causing the issue.
typedef void (__cdecl *mtSim_ResetODScan)(void);
mtSim_ResetODScan mpSim_ResetODScan;
if ((mpSim_ResetODScan = (mtSim_ResetODScan)GetProcAddress(mhSimDLL,
"_Sim_ResetODScan")) == NULL) return 0;
At this point mpSim_ResetODScan = 0x5E9741D0. Later on the function is called and when I debug the executable it breaks execution at the function call:
mpSim_ResetODScan();
Attempting to step into the function regenerates the access violation. The VS debugger reports that mpSim_ResetODScan still has the value 0x5E9741D0.
Commenting out all code inside the function in the dll makes no difference.
In the DLL:
extern "C" __declspec(dllexport) void __cdecl _Sim_ResetODScan(void);
Dependency Walker shows that the dll and exe are using MSVCR100.DLL version 10.0.30319.460.
Any suggestions on how I can debug this further or any hints on things I might have missed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试在调试器本身下正常运行程序,并在变量
mpSim_ResetODScan
周围放置一个数据断点 - 以查看它何时可能发生变化。似乎是缓冲区溢出的问题。Try running the program normally under debugger itself, and put a data breakpoint around variable
mpSim_ResetODScan
- to see when it is possibly changing. Seems to be problem of buffer overrun.