将带有指针的C++DLL导入C#
Import C++ DLL with pointer into C#
我知道我的问题有很多解决方案。我都试过了;然而,我还是会出错。
这些是DLL"KeygenLibrary.DLL"中的原始函数:
bool dfcDecodeMachineID(char* sEncodeMachineID, int iInLen, char* sMachineID, int& iOutLen);
bool dfcCreateLicense(char* sMachineID, int iLen, char* sLicenseFilePath);
要导入这个DLL,我尝试过:
方式1:
unsafe public class ImportDLL
{
[DllImport("KeygenLibrary.dll", EntryPoint = "dfcDecodeMachineID")]
unsafe public static extern bool dfcDecodeMachineID(char* sEncodeMachineID, int iInLen, char* sMachineID, ref int iOutLen);
[DllImport("KeygenLibrary.dll", EntryPoint = "dfcCreateLicense")]
unsafe public static extern bool dfcCreateLicense(char* sMachineID, int iLen, char* sLicenseFilePath);
}
方式2:
public class ImportDLL
{
[DllImport("KeygenLibrary.dll", EntryPoint = "dfcDecodeMachineID")]
public static extern bool dfcDecodeMachineID([MarshalAs(UnmanagedType.LPStr)] string sEncodeMachineID, int iInLen, [MarshalAs(UnmanagedType.LPStr)] string sMachineID, ref int iOutLen);
[DllImport("KeygenLibrary.dll", EntryPoint = "dfcCreateLicense")]
public static extern bool dfcCreateLicense([MarshalAs(UnmanagedType.LPStr)] string sMachineID, int iLen, [MarshalAs(UnmanagedType.LPStr)] string sLicenseFilePath);
}
然而,以上两种方式都给了我错误:
在DLL"KeygenLibrary.DLL"中找不到名为"function name"的入口点。
我该如何解决我的问题?非常感谢。
建议:
1) 在.dll上运行"dumpbin"以确认问题确实是名称篡改。
2) 如果是这样,请尝试此链接中的建议:
未找到入口点异常
a) 使用undname获取未修饰的名称
b) Set EntryPointy==损坏的名称
c) 设置CallingConvention=Cdecl
d) 为您的C#方法签名使用未标记的名称和签名
另请参阅此链接:
http://bytes.com/topic/c-sharp/answers/428504-c-program-calling-c-dll
Laurent。。。。您可以使用损坏的名称调用函数,如:
使用函数的全修饰名称调用函数
"?fnWin32Test2@@YAJXZ"
作为"Win32Test2"您可以将静态入口点指定为
"?fnWin32Test2@@YAJXY":
[DllImport("Win32Test.dll", EntryPoint= "?fnWin32Test2@@YAJXZ")] public static extern int fnWin32Test2();
并称之为:
System.Console.WriteLine(fnWin32Test2());
要查看未修饰的名称,请使用undname工具,如下所示:
`undname ?fnWin32Test@@3HA`
这会将修饰的名称转换为"long-fnWin32Test"。
问候,Jeff
相关文章:
- 将 C# DLL 导入 C++ 以用于 JNI
- C ++ DLL导入:函数调用返回错误的结果
- 编译器如何知道 dll 导入的函数?
- 尝试将C++dll导入C#时出现奇怪的System.BadImageFormatException
- 尝试将 c++ dll 导入 c 尖锐代码
- 如何从 dll 导入公共成员
- 将类从C#DLL导入到C 应用中
- 以下的 c# dll 导入声明是什么?
- 将 DLL 导入从 C# 移植到 C++
- ubuntu上带有mono的C#dll导入:不向dll收费
- DLL导入纯虚拟结构和unique_ptr由于Compressed_pair而无法编译
- 将C /CLI DLL导入C Win32控制台(Unmanage)
- 将唱歌的C#DLL导入C 项目
- C++ dll 导入 VBA(Excel) 与方法声明"_Something"
- DLL 导入:无法在 DLL "ImportDLL"中找到入口点"fnMultiply"
- 我对此C++函数的 C# DLL 导入进行封送处理有什么问题
- 将带有指针的C++DLL导入C#
- /Visual Studio中的MD不从Release配置中的msvcr100.dll导入
- C# DLL 导入失败:"The application has failed to start because its side-by-side configuration is incorrect
- 将非托管"QT" dll 导入 C# 给出 dllNotFoundException 但存在