开发者

DelayLoading a DLL and the associated .lib file

开发者 https://www.devze.com 2023-01-19 21:13 出处:网络
I am attempting to delay load wintrust.dll and crypt32.dll in my application (these are used to perform digital signature/publisher checks in a DLL). I am using VS2008. After adding these two DLLs as

I am attempting to delay load wintrust.dll and crypt32.dll in my application (these are used to perform digital signature/publisher checks in a DLL). I am using VS2008. After adding these two DLLs as entries in the Delay Load property in the Linker section of my project properties, I still get LNK4199 warnings that nothing was loaded from the DLL and LNK2019 errors unable to resolve symbols such as WinVerifyTrust.

Adding the following as entries to Additional Dependencies alleviates this problem: crypt32.lib and wintrust.lib. I now get no issues with linking. However, what I am wondering is how do I make sure this isn't being linked to the static lib? I do not want to link to the static lib because of potential licensing issues. I want to dynamically load the开发者_JAVA技巧 DLLs that are installed in Windows, and was hoping DelayLoad could help me do this without having to resort to LoadLibrary and GetProcAddress function calls.

Any information about all the different library usage/linking options would be greatly appreciated!

Thanks.


There is no static .lib for these. The SDK libraries are always import libraries, not static .libs because the corresponding Windows API lives in a DLL. No need to worry about this.


Delay loading doesn't free you from having to link to the lib file. Normally, DLLs are loaded as soon as your application starts. Delay loading just delays this until the first time you call a function from that DLL. Either way, you need to link to the lib file so that the linker can verify that the functions you are calling are actually present in the DLL.

If you don't want to link to the lib files, your only way out is to use LoadLibrary and GetProcAddress.


One tool that can help you determine if things are being linked as you expect is DependecyWalker: http://www.dependencywalker.com/ - specifically, in the case of delay-loads it marks them with a special symbol.


You may want to look at the Win32 API methods LoadLibrary and GetProcAddress.

0

精彩评论

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