#pragma comment(linker,"/delayload:xxx.dll") -- not supported in VS .NET

Started by
9 comments, last by helix 18 years, 5 months ago
The codebase I'm stuck using uses this pragma several times (for directx and other things). Their reasoning is because it will allow the plugin to still load even if you don't have the correct version of directx installed. This way it can be handled by telling the user what the problem is and how to resolve it. [This is something I'd REALLY like to be able to do with my games going forward so I can do away with a separate launcher exe that does this check for me.] So anyway, it appears that it is no longer supported post VS6.0 and after browsing the web for an explaination, it sounds like it never really was guaranteed to work in the first place so they just cut it. This isn't going to be a showstopper for me but it would sure be nice if there was a way to handle it. What can I do to gain this functionality? My project here is to create a plugin dll for another app and if you don't have every single dll installed, it simply won't show up in the plugin list at all currently -- not very elegant. Thanks!
Advertisement
You'll have to write code that defers runtime linking till later. And that'll probably mean setting up function pointer declarations and using LoadLibrary/GetProcAddress.

(If you don't already know this, LoadLibrary takes a path or filename of a DLL and returns a handle. GetProcAddress takes that handle and the function name and provides you with a pointer to the function. You assign that to a function pointer variable with the correct definition for the function in the DLL and you're good to go. Get it wrong and you'll almost certainly go down in flames)

One way to do this is to wrap those function pointers in another function in your dll (or in a macro) and check the pointer for null. If it is, then you GetProcAddress and hook up etc. At this point you could raise an exception or whatever if LoadLibrary or GetProcAddress return null or there was some other problem you detected. You could also just link everything all at once in whatever context makes the best sense.

If you're talking about dlls with just a handful of exports you want to link, this is no big deal. But for DirectX itself, you've got some fairly heavy lifting to do.

The basic problem is that if you let the OS do this runtime linking for you, it will succeed or fail before execution ever gets to code you have any control over (there may be some way to get your own code in even earlier but I sure don't know what it is)

I've never heard of that pragma before and I don't know what it does. It might set up something like what I described above with those macros.
That sounds like a huge pain in the ass and was about what I was expecting. I'll mark that one as "if time". Thanks for the input.
The conversion of function prototypes to function pointer declarations is pretty trivial and can be done with fairly simple text processing. But there's no really slick, easy way to automatically code the hookups - at least none I've come up with before running out of steam on the effort.
I'm using Visual C++ .NET 2003 Enterprise Architect, and setting a delay-load DLL worked perfectly fine.
Quote:The conversion of function prototypes to function pointer declarations is pretty trivial and can be done with fairly simple text processing. But there's no really slick, easy way to automatically code the hookups - at least none I've come up with before running out of steam on the effort.

Here's how:
// glext_funcs.hFUNC(int, wglSwapIntervalEXT, (int))// declaring function pointers (this goes in a header)#define FUNC(ret, name, params) extern ret (CALL_CONV *name) params;#include "glext_funcs.h"#undef FUNC// importing them// note: can also use GetProcAddress(hDLL, #name)#define FUNC(ret, name, params) *(void**)&name = SDL_GL_GetProcAddress(#name);#include "glext_funcs.h"#undef FUNC


HTH+HAND
E8 17 00 42 CE DC D2 DC E4 EA C4 40 CA DA C2 D8 CC 40 CA D0 E8 40E0 CA CA 96 5B B0 16 50 D7 D4 02 B2 02 86 E2 CD 21 58 48 79 F2 C3
Thanks Jan, I'll look into that.

Quote:Original post by trevaaar
I'm using Visual C++ .NET 2003 Enterprise Architect, and setting a delay-load DLL worked perfectly fine.


I assume you're building with the VC7 libs and runtimes? Are you using the pragma as I have in my subject line? I'm wondering how it works for you because I read online that it was specifically taken out of VS .NET.
The /delayload:foo.dll linker command line switch is supported even in the VC++ 2005 beta. Works fine for me.
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
Quote:Original post by Arild Fines
The /delayload:foo.dll linker command line switch is supported even in the VC++ 2005 beta. Works fine for me.


So you're not using the pragma but actually putting it in your project settings? Where would I put that? The command line is read only.

Maybe they put the functionality back in for 2005. Does it work for you in 2003?
Quote:Original post by helix
Quote:Original post by Arild Fines
The /delayload:foo.dll linker command line switch is supported even in the VC++ 2005 beta. Works fine for me.


So you're not using the pragma but actually putting it in your project settings?

Yes.
Quote:
Where would I put that?

Project Properties->Configuration Properties->Linker->Input->Delay Loaded DLLs
Quote:
The command line is read only.

You don't have a white "Additional options" box there?

Quote:
Maybe they put the functionality back in for 2005. Does it work for you in 2003?

Yes. And in 2002.

--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]

This topic is closed to new replies.

Advertisement