zoukankan      html  css  js  c++  java
  • 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);
            }
        }
    }
  • 相关阅读:
    《民工》随笔
    最近繁忙,暂停更新
    UVA 839 Not so Mobile
    UVA 310 Lsystem
    UVA 10602 Editor Nottoobad
    UVA 10562 Undraw the Trees
    UVA 327 Evaluating Simple C Expressions
    UVA 10954 Add All
    UVA 270 Lining Up
    UVA 699 The Falling Leaves
  • 原文地址:https://www.cnblogs.com/bent/p/4208726.html
Copyright © 2011-2022 走看看