在C#代码中调用C DLL
Call C++ dll in c# code
我试图在C#代码中调用C DLL。我的标题文件 -
#define MLTtest __declspec(dllexport)
class MLTtest testBuilder
{
public:
testBuilder(void);
~testBuilder(void);
int testfunc (int iNumber);
};
我的.cpp类
int testBuilder::testfunc (int iNumber)
{
return iNumber*2 ;
}
这是我使用该dll的C#代码。
class Program
{
[DllImport(@"C:SourcesOperationsOnline.DevBINDebugMlt1090d64.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "testfunc")]
public static extern int testfunc(int n);
static void Main(string[] args)
{
try
{
int x = testfunc (50);
}
catch (Exception ex)
{
}
}
}
,但我一直得到此例外例外:
无法在dll中找到名为" testfunc"的入口点 'c: sources operations inline.dev bin debug mlt1090d64.dll'。
问题是您尝试调用类成员方法。
放置在.cpp文件中流动函数(不是类成员(
extern "C" int __declspec(dllexport) testfunc(int iNumber)
{
return iNumber*2;
}
并在.cs
中更新[DllImport(@"C:SourcesOperationsOnline.DevBINDebugMlt1090d64.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int testfunc(int n);
相关文章:
- 如何安全地从 DLL 调用返回对象
- C++结构到德尔福记录dll调用
- 从 C#-DLL 调用函数的 C++ 失败
- 可视C++:XGBoost 从 DLL 调用时不起作用
- Unity3D的OpenCV dll调用导致FPS下降
- 创建一个C++DLL以从C#DLL调用方法
- 从 dll 调用 opencv 垫到 Windows 表单,图像出现故障
- 努力使用 C# 从本机 DLL 调用该方法
- WinAPI - GetLastError 在通过 COM ATL DLL 调用时始终返回 0
- 必须使用C DLL调用C#.NET方法
- 如何直接从 pdfium.dll 调用 v8 函数
- 为什么从 DLL 调用类方法需要虚拟说明符?
- VBA 中的多个 DLL 调用
- 挂钩VirtualAlloc在系统DLL调用时返回NULLPTR
- 无法从 C DLL 调用该函数
- DLL 调用涉及 strncpy() 的方法
- JNA从DLL调用C++对象-java.lang.IollegalArgumentException:Structure
- 德尔福动态DLL调用中的奇怪行为
- 从非托管 DLL 调用 UWP api
- boost::从 DLL 调用时日志格式不起作用