C# api 动态加载C++的DLL函数方法

来源:互联网 发布:编程是什么工作工资 编辑:程序博客网 时间:2024/05/18 03:07

C++函数如下:

// testdll3.cpp : Defines the entry point for the DLL application.
//

#include "stdafx.h"

BOOL APIENTRY DllMain( HANDLE hModule,
                       DWORD ul_reason_for_call,
                       LPVOID lpReserved
      )
{
    return TRUE;
}


extern "C" __declspec(dllexport) int add(int * a,int * b)
{
return *a + *b;
}

C#中动态加载方法:

首先写一个加载DLL文件的类:

 

 

以上方法编译.

调用:

 

 

 

原创粉丝点击