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 ...
随机推荐
- springmvc(三) 参数绑定、
前面两章就介绍了什么是springmvc,springmvc的框架原理,并且会简单的使用springmvc以及ssm的整合,从这一章节来看,就开始讲解springmvc的各种功能实现,慢慢消化 --W ...
- easyui点击搜索的时候获取不要文本框里面的值的问题
jsp的代码 <div id="tb"> <input id="AppID" placeholder="请根据申请人ID搜索&quo ...
- Luogu T7152 细胞(递推,矩阵乘法,快速幂)
Luogu T7152 细胞(递推,矩阵乘法,快速幂) Description 小 X 在上完生物课后对细胞的分裂产生了浓厚的兴趣.于是他决定做实验并 观察细胞分裂的规律. 他选取了一种特别的细胞,每 ...
- poj_3468: A Simple Problem with Integers (树状数组区间更新)
题目是对一个数组,支持两种操作 操作C:对下标从a到b的每个元素,值增加c: 操作Q:对求下标从a到b的元素值之和. 这道题也可以用线段树解,本文不做描述,下面分析如何用树状数组来解决这道题. 先把问 ...
- RxSwift 系列(二) -- Subject
前言 Subject是一个代理,它既是Observer,也是Observable.因为它是一个Observer,它可以订阅一个或多个Observable;因为它是一个Observable,它又可以被其 ...
- [luogu P2184] 贪婪大陆 [树状数组][线段树]
题目背景 面对蚂蚁们的疯狂进攻,小FF的Tower defence宣告失败……人类被蚂蚁们逼到了Greed Island上的一个海湾.现在,小FF的后方是一望无际的大海, 前方是变异了的超级蚂蚁. 小 ...
- 2017年1月1日 App Store中的所有应用都必须启用 App Transport Security安全功能
2017年1月1日 App Store中的所有应用都必须启用 App Transport Security安全功能,否则极有可能被拒! 在WWDC 2016开发者大会上,苹果宣布了一个最后期限:到20 ...
- Web Service--第一次接触web service
Web Service 首发于开源中国 1. 背景 中国移动短信网关需求,要能够发送短信.开发材料只有一个短信发送配置:包括ID,password,code,url.一个jar包还有一个老旧的html ...
- 关于html转换为pdf案例的一些测试与思考
由于工作所需,最近花时间研究了html转换为pdf的功能.html转换为pdf的关键技术是如何处理网页中复杂的css样式,通过在网上收集资料,发现目前html 转换为pdf的解决方案主要分为三类: 客 ...
- HDOJ2012-素数判定
Problem Description 对于表达式n^2+n+41,当n在(x,y)范围内取整数值时(包括x,y)(-39<=x<y<=50),判定该表达式的值是否都为素数. I ...