我可以在 DLL 延迟加载处理函数中使用 MSVCRT 函数吗?

发布于 2024-11-09 17:01:56 字数 753 浏览 0 评论 0原文

我已经按照中的说明将延迟加载添加到我的项目中 http://msdn.microsoft.com/en-us/library/151kt790.aspx

在“delayhlp.cpp”(DLL 加载帮助程序的示例实现)__HrLoadAllImportsForDll 中,我看到作者避免使用任何标准 C 库 (MSVCRT) 函数。我是否需要在处理程序函数中执行相同的操作(该函数将由示例 DLL 加载帮助程序调用)?

我认为作者的原因是有人可能会尝试延迟加载 MSVCRT 本身。我不会这样做。那么我使用 MSVCRT 函数安全吗?

背景信息 延迟加载第 3 方 DLL 的原因是两个版本之间存在函数签名更改,而我需要使用任一版本运行我的程序。然后,我提供一个简单的包装函数来根据需要调整 DLL 的函数签名。当 GetProcAddress 失败时,此函数由延迟加载处理程序 (__pfnDliFailureHook2) 注册。

一些测试。我在处理函数的开头添加了一个断点。我发现当断点被击中时, msvcrt.dllmsvcr90d.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故事未完 2024-11-16 17:01:56
        // Check to see if it is the DLL we want to load.
        // Intentionally case sensitive to avoid complication of using the CRT
        // for those that don't use the CRT...the user can replace this with
        // a variant of a case insenstive comparison routine.
        //

这是更相关的评论,对于那些不使用 CRT 的人。你不会有问题,CRT 总是由启动代码加载。

        // Check to see if it is the DLL we want to load.
        // Intentionally case sensitive to avoid complication of using the CRT
        // for those that don't use the CRT...the user can replace this with
        // a variant of a case insenstive comparison routine.
        //

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文