Visual Studio 2017 + C# + C++ and swig
来源:互联网 发布:没有输入的算法 编辑:程序博客网 时间:2024/05/16 06:30
一、下载swig程序
http://swig.org/download.html
二、VS2017中创建C# 控制台程序
三、创建C++的动态库文件
然后点击“Ok”按钮,创建C++项目
四、创建C++文件
文件cpp_file.h
#pragma once
#define CPP_EXPORTS
#ifdef CPP_EXPORTS
#define CPP_API __declspec(dllexport)
#else
#define CPP_API __declspec(dllimport)
#endif //
class CPP_API cpp_file
{
public:
cpp_file(void);
~cpp_file(void);
int times2(int arg);
};
文件cpp_file.cpp
#include "cpp_file.h"
cpp_file::cpp_file(void)
{
}
cpp_file::~cpp_file(void)
{
}
int cpp_file::times2(int arg)
{
return arg * 2;
}
然后编译cpp的项目,是可以编译通过的。
在cpp_file.h的同一个目录下,创建swig文件,cpp_file.i,内容如下:
%module cpp
%{
#include "cpp_file.h"
%}
%include <windows.i>
%include "cpp_file.h"
五、生成csharp和cpp文件。
swig.exe -csharp -c++ -outdir E:\work\test\testSWIG\csharp\swigcsharp\swig\gen cpp_file.i
六、将cpp_file_wrap.cxx加入到cpp项目,重新编译
然后将生成的cpp.dll文件拷贝到csharp项目的bin目录下。
七、将生成的cpp.cs, cpp_file.cs, cppPINVOKE.cs添加到csharp的项目文件里面
八、编写调用代码
class Program
{
static void Main(string[] args)
{
cpp_file file = new cpp_file();
int result = file.times2(20);
Console.WriteLine("result = " + result.ToString());
Console.ReadLine();
}
}
九、编译运行
输出的结果:
result = 40
- Visual Studio 2017 + C# + C++ and swig
- Visual Studio 2017 + java + C++ and swig
- SWIG c# 引用 c++dll
- 【c#】c#的调试(visual studio)
- Use HttpUtility and NameValueCollection in c# of Visual Studio 2010
- Visual Studio C#问题
- SWIG and Python(用SWIG将C/C++封装为Python扩展模块)
- visual studio 2017 创建C项目工程
- C#&visual studio
- Visual Studio 2005 and UnrealScript
- c#利用SWIG调用c++dll学习总结
- How to create a DLL with SWIG from Visual Studio 2010
- SWIG and Android
- SWIG and Android
- SWIG and Android
- The Visual Studio about C#
- The Visual Studio about C#
- Visual Studio C# Learning Notes
- 思考:智能化运维的发展
- protobuf(数据协议)
- SpringBoot打jar包放到Docker上
- PCA的数学原理
- iPhone8 和 iPhoneX 买哪个?听我的
- Visual Studio 2017 + C# + C++ and swig
- vim快捷键
- 暗恋这件小事
- TYPagerController 简单,强大,高度定制,页面控制器,水平滚动内容和标题栏,包含多种barStyle。 TYPagerController v2.0 重构优化代码,分离出TYPager
- 音频播放
- 2 The Vuri FAQ
- Android Studio工具使用
- PRO交易所和TOP链何时才能上线?
- 【Android】SeekBar的使用