用C#调用外部DLL

1.有时候需要用C#调用外部的dll,例如c++写的dll,首先需要保证dll的编译环境与本项目的环境是相同的,例如都是x86位或者x64位

2.调用声明和dll内的声明一致:

function Test_Add(A,B:Integer):Integer;stdcall;external 'Test.dll';

例如c++写的函数是两个int的参数,调用方式为stdcall,返回为int类型,在C#调用时需要同样声明。

[DllImport("Test.dll", EntryPoint = "Test_Add", ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]

public static extern int Add(int a, int b);

原文地址:https://www.cnblogs.com/zhoushiya/p/12107700.html