一、C#
自己写2D 3D算法库都要给别人用,所以好几年没有用过c# 了,调用一些
1、建立c++ 项目
.h 文件
#pragma once
#ifdef __DLLEXPORT
#define __DLL_EXP _declspec(dllexport)
#else
#define __DLL_EXP _declspec(dllimport)
#endif extern "C" __DLL_EXP int add(int a, int b);
.cpp
#include<stdio.h>
#include "myCppdll.h"int add(int a, int b)
{return a + b;
}
生成
2、C# 程序
using System;
using System.Runtime.InteropServices;namespace ConsoleApp1
{class Program{[DllImport(".\\MyDLL\\x64\\Release\\MyDLL.dll")]public extern static int add(int a, int b);static void Main(string[] args){int a = add(2, 3);Console.WriteLine(a);Console.WriteLine("ssss ");Console.ReadKey();}}
}
test