I need to take over someone else's C# code but I have never used C# before and have little experience with Visual Studio. The code fails to load some DLL. It looks something like this;
hModule = LoadLibrary("XXX.dll");
if (hModule == IntPtr.Zero)
{
MessageBox.Show("Load failed.", "Error");
return;
}
What are the possible causes to cause DLL to fail to load? If it is a path problem, I have placed the DLL in the same location as the executable. Do I need to manually add some references for this dll (using Visual Studio 2012)? Or could there be a problem with the dll? If so, how can this be verified?
I know this question is not suitable for Stack Overflow as it is too open-ended. But some possibilities raised can point me to the right direction. I would like to ask for some leeway before Stackoverflow members close this question or downvote it too many times. Thank you.
EDIT: After trying out the answer from Hans Passant, I got the error %1 is not a valid Win32 application
. Does this mean that something is wrong with the DLL? The same DLL can work with a Visual C++ code base but not with C# code. I also noticed there are some static library .lib in the code. But C# does not take in static libraries, if I am not wrong.