我可以在 DLL 延迟加载处理函数中使用 MSVCRT 函数吗?
我已经按照中的说明将延迟加载添加到我的项目中 http://msdn.microsoft.com/en-us/library/151kt790.aspx
在“delayhlp.cpp”(DLL 加载帮助程序的示例实现)__HrLoadAllImportsForDll
中,我看到作者避免使用任何标准 C 库 (MSVCRT) 函数。我是否需要在处理程序函数中执行相同的操作(该函数将由示例 DLL 加载帮助程序调用)?
我认为作者的原因是有人可能会尝试延迟加载 MSVCRT 本身。我不会这样做。那么我使用 MSVCRT 函数安全吗?
背景信息 延迟加载第 3 方 DLL 的原因是两个版本之间存在函数签名更改,而我需要使用任一版本运行我的程序。然后,我提供一个简单的包装函数来根据需要调整 DLL 的函数签名。当 GetProcAddress
失败时,此函数由延迟加载处理程序 (__pfnDliFailureHook2
) 注册。
一些测试。我在处理函数的开头添加了一个断点。我发现当断点被击中时, msvcrt.dll
和 msvcr90d.dll
等已经加载(从 Visual Studio 的模块窗格)。这是否意味着我可以安全地调用 CRT 函数?
I have already added delay loading to my project, using the instructions in
http://msdn.microsoft.com/en-us/library/151kt790.aspx
In the "delayhlp.cpp" (a sample implementation of the DLL load helper) __HrLoadAllImportsForDll
, I saw that the writer avoids using any Standard C Library (MSVCRT) functions. Do I need to do the same in my handler function, which will be called by the sample DLL load helper?
I think the writer's reason is that someone might try to delay-load MSVCRT itself. I'm not going to do this. Will it then be safe for me to use MSVCRT functions?
Background Info. The reason for delay-loading the 3rd party DLL is because there is a function signature change between two versions, and I need to run my program using either version. I then provide a simple wrapper function to adapt the DLL's function signature to the one needed. This function is registered by the Delay-Load Handler (__pfnDliFailureHook2
), when GetProcAddress
fails.
Some testing. I added a breakpoint at the beginning of my handler function. I found that when the breakpoint is hit, the msvcrt.dll
and msvcr90d.dll
etc are already loaded (from Visual Studio's Modules pane). Does it mean that I can call CRT functions safely?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是更相关的评论,对于那些不使用 CRT 的人。你不会有问题,CRT 总是由启动代码加载。
That's the more relevant comment, for those that don't use the CRT. You won't have a problem, the CRT is always loaded by the startup code.