学习网站 现状,wordpress错误代码403,云开发小程序源码,惠州网络营销公司看了第一篇感觉没啥用对吧#xff0c;来点稍微有用的。
1、先建个c#工程#xff0c;依次 file - new - project#xff0c;选择 visula c# - console application#xff0c;写工程名#xff0c;点 ok。 2、再建个c dll工程。依次 file - add - new …看了第一篇感觉没啥用对吧来点稍微有用的。
1、先建个c#工程依次 file - new - project选择 visula c# - console application写工程名点 ok。 2、再建个c dll工程。依次 file - add - new project。选择 visual - win32 console application点 ok - next选择 dll - finish。 3、建立cli工程。依次 file - add - new project。选择 visula c - clr - class library写工程名点 ok。 4、创建结束开始配种啊呸配置。
1、c#工程默认平台any cpu强迫症犯了改成x86编译下生成目标debug路径.\bin\x86\debug。
2、修改c工程输出目录、cli工程输出目录、cli工程库引入路径等为上方目录。
3、修改cli引入头文件路径为包含CppDll.h的路径。
4、依次编译c工程cli工程
5、c#工程导入CliDll依次选择 c#工程 - references - 点右键 - add reference - browse - 选择debug路径下由cli工程生成的dll文件。
6、编译c#工程最后运行。 附源码
github仓库项目地址gitgithub.com:fx-odyssey/CS_Cli_Cpp.gitvs2008工程打开可直接运行
//CppDll.h
#pragma once
#include stdio.h
#include stdlib.h#ifdef CPPDLL_EXPORTS#define CPP_EXPORTS __declspec(dllexport)
#else#define CPP_EXPORTS __declspec(dllimport)
#endifextern C CPP_EXPORTS int Add(int a, int b);extern C CPP_EXPORTS int Sub(int a, int b);extern C CPP_EXPORTS int Mul(int a, int b);extern C CPP_EXPORTS int Div(int a, int b);***************************************// CppDll.cpp
#include stdafx.h
#include CppDll.hint Add(int a, int b)
{return a b;
}int Sub(int a, int b)
{return a - b;
}int Mul(int a, int b)
{return a * b;
}int Div(int a, int b)
{return a / b;
}**************************************// CliDll.h
#pragma once
#include iostream
#include CppDll.husing namespace System;
using namespace System::Runtime::InteropServices;
using namespace System::Collections::Generic;
using namespace System::Collections;
using namespace std;#pragma comment(lib, CppDll.lib)
#pragma managed
namespace CliDll {public ref class Arith{public:Arith();~Arith();int AddCli(int a, int b);int SubCli(int a, int b);int MulCli(int a, int b);int DivCli(int a, int b);};
}**************************************// CliDll.cpp
#include stdafx.h
#include CliDll.husing namespace CliDll;CliDll::Arith::Arith(){}CliDll::Arith::~Arith(){}int CliDll::Arith::AddCli(int a, int b)
{return Add(a, b);
}int CliDll::Arith::SubCli(int a, int b)
{return Sub(a, b);
}int CliDll::Arith::MulCli(int a, int b)
{return Mul(a, b);
}int CliDll::Arith::DivCli(int a, int b)
{return Div(a, b);
}*************************************//Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CliDll;namespace CSProject
{class Program{static void Main(string[] args){Arith arith new Arith();int back1 arith.AddCli(1, 2);Console.WriteLine(back1.ToString());int back2 arith.SubCli(3, 4);Console.WriteLine(back2.ToString());int back3 arith.MulCli(4, 5);Console.WriteLine(back3.ToString());int back4 arith.DivCli(8, 4);Console.WriteLine(back4.ToString());Console.ReadLine();}}
}