views:

38

answers:

4

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

A: 

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

Joshua Rodgers
I don't follow... I already mentioned that I'd like to do this without having to use LoadLibrary and GetProcAddress by using DelayLoad to load the DLL.
sohum
It's the only way I'm aware of being able to load a DLL at run-time without having to link to some library defining the symbols.
Joshua Rodgers
http://msdn.microsoft.com/en-us/library/151kt790%28v=VS.80%29.aspx
sohum
I guess my bigger question is that it inherently seems that I'm linking to that library statically when doing this. Is this not the case?
sohum
The .lib file for a DLL really only specifies the addresses and symbol names in the DLL so the linker can resolve the symbols in code.
Joshua Rodgers
+1  A: 

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.

casablanca
+3  A: 

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.

Hans Passant
Cool, that's exactly what I wanted to know. Do you know if there is any documentation that confirms the same?
sohum
The DLL in which an API function lives is documented in the MSDN Library page for them. You can get confirmation from http://stackoverflow.com/questions/3936468/delayloading-a-dll-and-the-associated-lib-file/3936573#3936573
Hans Passant
@Hans: That was the SO version of a Rick Roll.
John Dibling
@John: I had to look that up, yup. Thanks for the meme.
Hans Passant
+2  A: 

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.

Michael Burr
Cool, that shows that it's linked to Crypt32.dll and Wintrust.dll.
sohum