How to call C/C++ sytle function from C# solution?
1. Write native(unmanaged) code with C/C++, and make sure compile it as a DLL, the sample is as below
#include <iostream>
using namespace std;
extern "C"
{
_declspec(dllexport) int AddTwoNumber(int x, int y);
}
int AddTwoNumber(int x, int y)
{
return x+y;
}
2. Write managed code with C#, we can put it in a console application, like below:
static void Main(string[] args)
{
int result = AddTwoNumber(2, 77);
Console.WriteLine(result);
Console.Read();
}
[DllImport("E:\\TestTools\\UnManagedSolution\\Debug\\UnManagedSolution.dll", CallingConvention = CallingConvention.Cdecl)] // full path to reference the dll file
//[DllImport("E:\\TestTools\\UnManagedSolution\\Debug\\UnManagedSolution.dll", CallingConvention=CallingConvention.StdCall)] // just different CallingConvention
//[DllImport("UnManagedSolution.dll"), CallingConvention] // make sure copy the dll to the same folder with exe file
public extern static int AddTwoNumber(int x, int y);
Now it just works, try it! ^_^
How to call C/C++ sytle function from C# solution?的更多相关文章
- 《Walking the callstack(转载)》
本文转载自:https://www.codeproject.com/articles/11132/walking-the-callstack Download demo project with so ...
- GenomicRangeQuery /codility/ preFix sums
首先上题目: A DNA sequence can be represented as a string consisting of the letters A, C, G and T, which ...
- Private-code MaxCounter
No need for a double cycle: : You are given N counters, initially set to 0, and you have two possibl ...
- js常用功能汇总
var Utils = function() { this.Tools; this.ui; }; Utils = new Utils(); Utils.prototype.Tools = { year ...
- On Caching and Evangelizing SQL
http://www.oracle.com/technetwork/issue-archive/2011/11-sep/o51asktom-453438.html Our technologist ...
- 通过百度echarts实现数据图表展示功能
现在我们在工作中,在开发中都会或多或少的用到图表统计数据显示给用户.通过图表可以很直观的,直接的将数据呈现出来.这里我就介绍说一下利用百度开源的echarts图表技术实现的具体功能. 1.对于不太理解 ...
- Python:staticmethod vs classmethod
Being educated under Java background, static method and class method are the same thing. But not so ...
- SharePoint Solutions Deployment-PowerShell
之前群里有人问到了这个,项目一期开发结束后正好整理了一下,发上来分享一下,也是从谷歌搜索里面学来的,大家要用好搜索哈 $ver = $host | select version if ($ver.Ve ...
- 机器学习:形如抛物线的散点图在python和R中的非线性回归拟合方法
对于样本数据的散点图形如函数y=ax2+bx+c的图像的数据, 在python中的拟合过程为: ##最小二乘法 import numpy as np import scipy as sp import ...
随机推荐
- 面向对象设计模式——观察者(OBSERVER)模式
定义 定义对象间的一种一对多的依赖关系,当一个对象的状态发生改变时,所有依赖于它的对象都得到通知并被自动更新. Observer模式描述了如何建立这种关系.这一模式中的关键对象是目标(subject ...
- (转)Sublime Text中文乱码问题
Sublime Text 2是一个非常不错的源代码及文本编辑器,但是不支持GB2312和GBK编码在很多情况下会非常麻烦.不过Sublime Package Control所以供的插件可以让Subli ...
- HDU1124 Factorial
Problem Description The most important part of a GSM network is so called Base Transceiver Station ( ...
- PHP环境搭建——Apache
1.PHP环境安装前我们需要知道PHP给我们带来的功能是什么? Php主要用在三个领域 (1) 网站和web应用程序 (2) 命令行脚本 (3) 桌面(GUI)应用 ...
- Android Handler 机制 - Looper,Message,MessageQueue
Android Studio 2.3 API 25 从源码角度分析Handler机制.有利于使用Handler和分析Handler的相关问题. Handler 简介 一个Handler允许发送和处理M ...
- 一种轻便且灵活的js模板的思路
一种轻便且灵活的js模板的思路 项目地址:https://github.com/j20041426/template 思路背景 在Vue.React.Angular等大前端框架异军突起的今天,写前端时 ...
- Java 字符排序问题
Java 字符排序问题 未专注于排序算法,而是写了一个MyString类,实现了comparable的接口,然后用Arrays的sort方法来实现排序.我觉得这道题的难度在于如果比较两个.因为大小写的 ...
- Linux 下 安装jdk 1.7
Linux 下 安装jdk 1.7 参考百度经验 http://jingyan.baidu.com/album/ce09321b7c111f2bff858fea.html?picindex=6 第一步 ...
- apt-get命令失效
1.linux体系区分 a.ded体系,例如debian系统.ubuntu系统.使用apt-get命令: 例如:sudo apt-get install apache2 b.rpm体系,例如redha ...
- factorOne cannot be&nb…
factorOne cannot be resolved or is not a field 现象描述: Eclipse的使用时会在代码处出现警告factorOne cannot be resolve ...