目录
创建dll
新建dll工程
添加def导出文件
【源文件】》【添加新建项】》【模块定义文件def】
def文件格式,EXPOTS后面紧跟导出的函数名称 @数字累加
LIBRARY
EXPORTS
ShowMessage @1
导出函数实现
#include "stdafx.h"
#include "stdio.h"
#define CMDEXECUTEDLL_API __declspec(dllexport)
//设置多应用共享全局数据和对象
#pragma data_seg("cdllshard")
int count = 0;
#pragma data_seg()
#pragma comment(linker, "/Section:cdllshard,rws") //声明共享段
//
//导出函数实现
CMDEXECUTEDLL_API int ShowMessage()
{
count++;
printf("ShowMessage > %d\r\n", count);
return count;
}
C#调用dll
//声明调用
[DllImport("clib.dll", EntryPoint = "ShowMessage", CallingConvention = CallingConvention.Cdecl)]
public static extern int ShowMessage();
static void Main(string[] args)
{
ShowMessage();
Console.ReadKey();
}
经过测试,count可以实现多进程操作。