i'm working on a C++ project with Visual Studio 2017.
I have SDL2 installed in a custom directory (not in PATH).
I'm creating a DLL which uses SDL2.
I added the SDL2 directory in the project properties (VC++ Directories -> Library Directories, I also tried with Reference Directories) and it compile correctly.
Then in the Core program, I load my DLL with LoadLibraryA and it fail (getLastError() tell me error 126).
I looked with Dependency Walker and it cannot find SDL2.DLL.
I also looked with Process Monitor, I saw it first looked for SDL2.dll in the current directory, then all directories in the PATH environment variable. Since SDL2 is not in a PATH directory, the loading fail, end of the story, me is sad.
Of course I could add the SDL2 installation directory to the PATH variable, but I don't want to, because of reasons.
Is there something I should change in my configuration?
Thanks.
SOLUTION:
I found a workaround.
My Core program load lib.dll, which needs SDL2.dll.
Instead I can create another dll, like libloader.dll. In this one I use SetDllDirectory to tell where is located SDL2.dll, and then I use LoadLibraryA to load lib.dll.
Since I have a single entry point in lib.dll, I just have to wrap it in the libloader.dll entry point.
That way, I will never have to put the location of SDL2.dll in the Core.