#### Archived

This topic is now archived and is closed to further replies.

## Recommended Posts

How does one go about loading DLLs dinamicly? I''m designing a 3D engine which supports either OpenGL or Direct3D at any one given time, but I don''t want the overhead of having Direct3D dlls loaded, if I''m using OpenGL instead... I''m searching for something like this: if( TargetAPI == OpenGL ) { dllLoad("opengl32.dll2); }; Also, do I still need to have the libraries defined in the Projects setting area after having dinamic dll loading? thanx for any input you might have...

[Hugo Ferreira][Positronic Dreams][]
"Research is what I''m doing when I don''t know what I''m doing."
- Wernher Von Braun (1912-1977)

##### Share on other sites

and then you would need to load each function dynamically with "GetProcAddress".

i do not suggest this approach for DirectX.

peace.

To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.

##### Share on other sites
Just to give a bit more detail on GetProcAddress, you need to do this:
IDirect3D8 * WINAPI(*Direct3DCreate8)(UINT)      = (IDirect3D8 *WINAPI(*)(UINT))GetProcAddress(library, "Direct3DCreate8");

For every function you use from the DLL. You need to check the pointer for NULL afterwards. You might also want to use a typedef to improve readability. You don't need to include the d3d8.lib file in your project anymore.

In response to Jenova's comment, I would say one of the few times you want to use dynamic loading is with DirectX. All you need to do is get the address of the Direct-whatever-Create function. Once youve called that you have a fully fledged COM object and you never need to GetProcAddress again.

This is the worst thing about it though. I had a horrible bug in my program because I missed the WINAPI calling convention off the function pointer. The program worked fine in debug mode, but when I switched to release mode it went crazy. Luckily I know asm, so I worked through the disassembly and found that there was an unbalanced stack access. This meant that when I returned from the function it actually went two places up the call stack. That caused the back half of my init function to be missed out and it all went downhill from there...

Not that Im trying to put you off

Edited by - Krunk on January 16, 2002 10:12:01 AM

• ### Forum Statistics

• Total Topics
628375
• Total Posts
2982318

• 10
• 9
• 14
• 24
• 11