我正在使用Visual Studio 2012(11.0.51106.01 Update 1)在64位Windows 7盒子上进行开发.
我有一个支持项目,将一些C代码编译成(32位)DLL.在我的标题中,我有:
#define RET_TYPE(type) _declspec(dllexport) type __stdcall
RET_TYPE(int) test_dll_call(int invar);
Run Code Online (Sandbox Code Playgroud)
在我的C文件中,我有:
RET_TYPE(int) test_dll_call(int invar)
{
int retVal = 4 * invar;
return retVal;
}
Run Code Online (Sandbox Code Playgroud)
我还有一个(32位)WPF C#应用程序,它将DLL加载到类中,如下所示:
[DllImport("MyDll.dll", CharSet = CharSet.Ansi, BestFitMapping = true, ThrowOnUnmappableChar = true)]
public static extern int test_dll_call(int invar);
Run Code Online (Sandbox Code Playgroud)
包装如下:
public void Wrap_TestDllCall()
{
try
{
int outTest = 0;
int invar = 3;
outTest = test_dll_call(invar);
}
catch (Exception ex)
{
dllError = ex.ToString();
}
}
Run Code Online (Sandbox Code Playgroud)
当我在我的开发框中的调试器中运行它时,这很好.如果我将所有相关文件复制到一个单独的文件夹并从那里运行它,它工作正常.
如果我将所有必要的文件夹复制到另一台运行32位Windows XP SP3的计算机上,我会收到以下错误:
System.DllNotFoundException: …Run Code Online (Sandbox Code Playgroud)