关于mysql:C调用C-动态链接库dll

4次阅读

共计 669 个字符,预计需要花费 2 分钟才能阅读完成。

在过程中发现两种办法解决问题:一种是非托管 C ++ 创立的 dll 库,须要用静态方法调用。这种办法无奈在 C# 的 reference 中间接援用,而是要用动态调用的办法,其余博客曾经介绍的很详尽,惟一须要补充的是,C# 文件须要先:

`using System.Runtime.InteropServices;`

之后才能够调用 [DllImport] 办法。
另一种办法是间接应用 CLR,生成托管 C ++dll 库。
创立流程
例程如下
C++ dll:

// CPPlibdemo.h
#pragma once

using namespace System;


namespace CPPlibdemo {

    public ref class Class1
    {
        // TODO: Add your methods for this class here.
    public:
            String ^getgreating(){return "hello world";}
    };
}

C# 语言:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CPPlibdemo;

namespace ConsoleApplication5
{
    class Program
    {static void Main(string[] args)
        {Class1 clrdemo = new Class1();


            Console.Write(clrdemo.getgreating());
            Console.ReadLine();}
    }
}
正文完
 0