I'm trying to load my 32/64 bit native dll's using the same DllImport call.
Directory structure:
root:
- application.exe
- /win64/
- stb_image.dll
- /win32/
- stb_image.dll
I tried using this solution but as you can see no succes.
For example this function call:
[DllImport("stb_image.dll")]
private static extern IntPtr stbi_load(string filename, ref int x, ref int y, ref int n, int req_comp);
But it doesn't work as I get an DllNotFoundException.
The way I'm using SetDllDirectory:
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
SetUnmanagedDllDirectory();
GameConfiguration config = new GameConfiguration();
config.FPSTarget = 60;
config.FixedFPS = true;
config.Resizable = false;
TestGame game = new TestGame(config);
game.Run();
}
public static void SetUnmanagedDllDirectory()
{
string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
path = Path.Combine(path, IntPtr.Size == 8 ? "win64 " : "win32");
if (!SetDllDirectory(path)) throw new System.ComponentModel.Win32Exception();
}
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern bool SetDllDirectory(string path);
}
It's the first call in my program so it should've set the correct path. It also returns true.
But if I put the (in my case) 64 bit native dll in the exe's directory then it works even tho I set the DllDirectory to a different path.
Any help?