OpenGL.dll and LoadLibrary

When I call LoadLibrary with “opengl.dll” as parameter, it always returns error code 1114 => Initialization of the opengl.dll failed.

What can I do to load the dll with LoadLibrary correctly?

Firstly, the name of the DLL is not opengl.dll, but opengl32.dll.
Secondly, why do you use LoadLibrary? your program will load it automatically, if it uses an OpenGL function, uses the opengl32.lib and is located at:
or the directory of your executable.

Which language do you use? C/C++ or Delphi?

I use C++…

I wanna use LoadLibary to make a proxy dll.

I don’t know what do you mean by proxy dll, but since you use C++, I don’t think you need to use LoadLibrary, because you can add include directives to automatically use the OpenGL library:

#include “gl/gl.h”
#include “gl/glu.h”
#include “gl/glaux.h”

However if you insist, you can write:

HINSTANCE Handle = LoadLibrary(“opengl32.dll”);

Then, to find the entry address of every function you must use the function GetProcAddress, and pass to it the handle you got and the name of the procedure. This way you’ll get a CALLBACK function that you can use. I can’t help you with CALLBACK functions because I am a Delphi programmer and we have Procedural types instead of CALLBACK functions which differ in declaration.


“Explicit” linking (using LoadLibrary()) has advantages over “implicit” linking (linking with the stub library):

1> It makes it so that the client of the library doesn’t die with an ugly messagebox at launch in the case the library is unavailable.

2> It doesn’t load libraries it does not need, wasting computer resources. For instance, an engine which supports both D3D and OpenGL benefits from explicit linking because it only needs toload one or the other library at run time. With implicit linking, both libraries get loaded, taking more time and memory.

There’s a section in the MSVC docs about the advantages and disadvantages of each which delves into more detail.