【发布时间】:2015-11-02 08:04:00
【问题描述】:
我想在 C# 中加载一个 C++ dll(VS2012,C++ dll 也在 VS2012 C++ 中创建),在 C++ dll 中我使用了一个由 MATLAB 生成的共享库,并使用了 deploytool。(我在 C# 和 C++ 中的配置程序是 x64 并且共享库也在 64 位版本的 MATLAB 中生成)。
我使用以下代码加载库,然后收到错误代码 1008:
[DllImport("kernel32.dll",CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr LoadLibrary(string libname);
...
IntPtr handle = LoadLibrary("libName.dll");
if(handle == IntPtr.Zero)
{
int errorCode = Marshal.GetLastWin32Error();
//at this point error code will be 1008.
}
请帮我解决这个问题!
提前致谢。
【问题讨论】:
-
当我在
if(handle == IntPtr.Zero)行插入断点然后继续时,我收到错误代码 1008,当我在没有任何断点的情况下运行时,收到的错误代码将为 193。但是,如上所述,所有我使用的程序是 x64 配置或 64 位版本。
标签: visual-studio-2012 visual-c++ matlab-deployment loadlibrary error-code