开发者

Can I use MSVCRT functions in my DLL Delay-Load Handler function?

开发者 https://www.devze.com 2023-03-09 02:51 出处:网络
I have already added delay loading to my project, using the instructions in http://msdn.microsoft.com/en-us/library/151kt790.aspx

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 开发者_如何学Cbetween 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?


        // 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号