Can I use MSVCRT functions in my DLL Delay-Load Ha

2019-09-18 13:30发布

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?

标签: dll msvcrt
1条回答
迷人小祖宗
2楼-- · 2019-09-18 14:10
        // 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.

查看更多
登录 后发表回答