Issues loading DLL
I'm trying to load a C++ DLL and use it's function
GetEngineVersion
to get the engine version to find out installed version of the game. I need it to be loaded from Properties.Settings.Default.InstallPath, "LS3DF.dll"
. I get an error 126 and can't fix it.
I can use the DLL function if i use [DllImport]
but that only uses fixed path.
I need it to be dynamic and load the path from InstallPath
setting. i'm using .NET Framework 4.7.2, platform is set to x86
here is a code for a button i use for testing:
8 Replies
It may be that the DLL is compiled for x64, or has dependencies of its own that can't be found and loaded (possibly because they're located somewhere Windows doesn't look). I haven't used it in ages, but I think you can still find a tool called Dependency Walker, it would tell you what other DLLs a given DLL depends on. Give it your DLL and see what it says.
I don't know much about native win32 programming, but while you do specify the full path to the main DLL, if it has dependencies, the OS is going to look for them according to some default logic. There are WinAPI functions such as SetDllDirectory and AddDllDirectory that you can use to control where the system looks for libraries, and even LoadLibraryEx which accepts flags to further control this.
Frankly, this is the sort of task where I think ChatGPT or some other LLM can help you out reasonably well.
I tried chatGTP to help with the issue but i get stuck in a loop of "include more debugging messags to check if path is correct". Path is correct, dll is there, dll is not corrupted, dll is c++ x86 from 2002
i got a code from some other person that needed the same thing so i adapted their code for my usage and i still get error 126
and when i use the [DllImport] it works
Gosh, that’s annoying. Have you also tried making sure that DLL doesn’t have any dependencies?
i don't really know how i can tell that it doesn't need any using the tool
Please don't upload any potentially harmful files @Richard01_CZ, your message has been removed
whoops, wanted to share the dll
This is the code i have that should work but i still get error 126
i used chat gpt to make some basic broken code, fixed it and it seems to be working apart from the dll failing to load
I've also checked some other users that had the same issue and the solution is basically the same as i have it here
only thing i didn't try is running the app as admin
nope, no luck
figured it out
the DLL was loading successfully but it was looking for dependencies in the application directory, not in the directory the DLL is placed in
by calling the function
SetDllDirectory(installPath);
from imported kernel dll, it was able to load and function correctly
installPath
being a string from Properties.Settings.Default.InstallPath
as that's where i store user selected game directory.