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

在过程中发现两种办法解决问题:一种是非托管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();
        }
    }
}

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理