There are several ways to handle this, depending on the libraries and their names / locations:
If both have the same name (opengl32.dll), you need to add the location of the Mesa DLL to the search path so that it is searched to the system directory. Order catalogs are checked in detail here . As you can see, $PATH comes last after the system, so you cannot just add a directory to it. However, you can use the second step ("Current directory") by setting the working directory to the path containing the mesa files. Typically, this means running the application using the absolute path in the directory containing the files.
Nevertheless, it is still not particularly pleasant. If possible, you should use
LoadLibrary and check if there is an environment variable (
OPENGL_LIBRARY_PATH ) when the application starts. Assuming the export from
opengl32.dll and the Mesa DLL are the same, you can do something like:
void LoadExports() { char location[MAX_PATH]; getenv("OPENGL_LIBRARY_PATH", location); HMODULE oglLib = LoadLibrary(location); function1 = GetProcAddress(oglLib, "glVertex2f"); ... }
This will work just fine, doing almost what you want.
However, if you want to do this, you cannot import opengl32.dll , which you probably do, you need to dynamically link everywhere. Do not mess with opengl32.lib and everything should be in order. Depending on how many functions you use, there may be a pain in customization, but the code can be easily written in a script and only need to be done once, you can also use static variables to cache the results throughout the life of the program. It is also possible to use different function names for different libraries, although this requires a bit more logic, so I will leave you the data.