码迷,mamicode.com
首页 > 编程语言 > 详细

C#调用C++库(dll)的函数

时间:2015-01-07 18:30:14      阅读:292      评论:0      收藏:0      [点我收藏+]

标签:

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);
        }
    }
}

 

C#调用C++库(dll)的函数

标签:

原文地址:http://www.cnblogs.com/bent/p/4208726.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!