我有一个在运行时加载DLL的C#应用程序。DLL 是 32 位的,因此它是应用程序。
我尝试使用来自以下位置的加载库:
[DllImport("kernel32.dll")]
private static extern IntPtr LoadLibrary(string dllToLoad);
[DllImport("kernel32.dll")]
private static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName);
[DllImport("kernel32.dll")]
private static extern bool FreeLibrary(IntPtr hModule);
但没有结果;它总是返回IntPtr.Zero
。我也尝试使用
[DllImport("%windir%\SysWOW64\kernel32.dll")]
private static extern IntPtr LoadLibrary(string dllToLoad);
[DllImport("%windir%\SysWOW64\kernel32.dll")]
private static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName);
[DllImport("%windir%\SysWOW64\kernel32.dll")]
private static extern bool FreeLibrary(IntPtr hModule);
但这样,应用程序在调用 LoadLibrary 时会得到"System.Windows.Markup.XamlParseException"异常。
以前有人遇到过这个问题吗?
你的 C# exe 必须编译为 32 位。
检查此页面以获取错误代码详细信息:
https://msdn.microsoft.com/en-us/library/ms681382(v=vs.85(.aspx
ERROR_BAD_EXE_FORMAT 193 (0xC1(
%1 不是有效的 Win32 应用程序。