www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Implicit Delayed DLL Loading?

reply %u <wfunction hotmail.com> writes:
Hi,

I was wondering, is there a way to tell the compiler to implicitly delay-load
a DLL, like you can with the /DELAYLOAD:DllName option in Visual C++?

I was thinking that, if there isn't, it might be useful to extend the "lazy"
keyword to cover functions (or maybe create a  delay or  lazy annotation), so
as to tell the compiler to delay-load a function. This is very useful for
coding, as delay-loading DLLs by hand becomes a pain when the number of
functions increases to more than a handful.

Thank you!
Jan 04 2011
parent reply "Vladimir Panteleev" <vladimir thecybershadow.net> writes:
On Tue, 04 Jan 2011 11:03:45 +0200, %u <wfunction hotmail.com> wrote:

 I was wondering, is there a way to tell the compiler to implicitly  
 delay-load
 a DLL, like you can with the /DELAYLOAD:DllName option in Visual C++?
Well, first of all DELAYLOAD is a linker option, and it doesn't look like OPTLINK supports it. You could have a look at how Derelict loads and binds entire APIs (e.g. SDL) at runtime. -- Best regards, Vladimir mailto:vladimir thecybershadow.net
Jan 04 2011
parent reply Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
I think Derelict loads the DLLs at load time, before the call to
main() (I could be wrong here). Delayed loading is when a DLL is
imported at runtime when there's an actual call made that requires the
DLL, it doesn't get preloaded at load time.

On 1/4/11, Vladimir Panteleev <vladimir thecybershadow.net> wrote:
 On Tue, 04 Jan 2011 11:03:45 +0200, %u <wfunction hotmail.com> wrote:

 I was wondering, is there a way to tell the compiler to implicitly
 delay-load
 a DLL, like you can with the /DELAYLOAD:DllName option in Visual C++?
Well, first of all DELAYLOAD is a linker option, and it doesn't look like OPTLINK supports it. You could have a look at how Derelict loads and binds entire APIs (e.g. SDL) at runtime. -- Best regards, Vladimir mailto:vladimir thecybershadow.net
Jan 04 2011
parent reply "Vladimir Panteleev" <vladimir thecybershadow.net> writes:
On Tue, 04 Jan 2011 12:44:07 +0200, Andrej Mitrovic  
<andrej.mitrovich gmail.com> wrote:

 I think Derelict loads the DLLs at load time, before the call to
 main() (I could be wrong here). Delayed loading is when a DLL is
 imported at runtime when there's an actual call made that requires the
 DLL, it doesn't get preloaded at load time.
Technically you have to ask Derelict to load a DLL explicitly, like this: DerelictSDL.load(); Anyway, it shouldn't be hard to implement "real" delayed loading on top of SDL's methods. In fact, you could even enumerate all function variables at the module level, and generate delay-loading code at compile time. This way you only need to mention any specific DLL function once. -- Best regards, Vladimir mailto:vladimir thecybershadow.net
Jan 04 2011
parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
I can't find anything in optlink's -help, and the docs don't mention
this feature so it probably can't delay load DLLs. But afaik optlink
isn't used on Linux, so whichever linker is used there might have the
delayed loading feature.
Jan 04 2011