C#调用C++库(dll)的函数
C++函数定义
extern "C" __declspec(dllexport) void ThundbirdPhaseLocalFolder(const string* localFolderPaths,const string* zipFolders, bool (*isProcess)()) { const char* localFolderPath = localFolderPaths->c_str(); const char* zipFolder = zipFolders->c_str(); }
C#函数定义
namespace TestThunderbirdZipperCSharp { class CPPDLL { [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate bool IsProcess(); [DllImport("ThunderbirdLocalFolderZipper.dll")] public static extern void ThundbirdPhaseLocalFolder([MarshalAs(UnmanagedType.LPWStr)]string localFolderPath, [MarshalAs(UnmanagedType.LPWStr)]string zipFolder, [MarshalAs(UnmanagedType.FunctionPtr)] IsProcess isProcess); } }
C#调用
namespace TestThunderbirdZipperCSharp { class Program { static bool flag = true; static bool callback() { return flag; } static void Main(string[] args) { string localFolderPath = ""; string zipFolder = ""; CPPDLL.ThundbirdPhaseLocalFolder(localFolderPath, zipFolder, callback); } } }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。