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?的更多相关文章

  1. 《Walking the callstack(转载)》

    本文转载自:https://www.codeproject.com/articles/11132/walking-the-callstack Download demo project with so ...

  2. GenomicRangeQuery /codility/ preFix sums

    首先上题目: A DNA sequence can be represented as a string consisting of the letters A, C, G and T, which ...

  3. Private-code MaxCounter

    No need for a double cycle: : You are given N counters, initially set to 0, and you have two possibl ...

  4. js常用功能汇总

    var Utils = function() { this.Tools; this.ui; }; Utils = new Utils(); Utils.prototype.Tools = { year ...

  5. On Caching and Evangelizing SQL

    http://www.oracle.com/technetwork/issue-archive/2011/11-sep/o51asktom-453438.html   Our technologist ...

  6. 通过百度echarts实现数据图表展示功能

    现在我们在工作中,在开发中都会或多或少的用到图表统计数据显示给用户.通过图表可以很直观的,直接的将数据呈现出来.这里我就介绍说一下利用百度开源的echarts图表技术实现的具体功能. 1.对于不太理解 ...

  7. Python:staticmethod vs classmethod

    Being educated under Java background, static method and class method are the same thing. But not so ...

  8. SharePoint Solutions Deployment-PowerShell

    之前群里有人问到了这个,项目一期开发结束后正好整理了一下,发上来分享一下,也是从谷歌搜索里面学来的,大家要用好搜索哈 $ver = $host | select version if ($ver.Ve ...

  9. 机器学习:形如抛物线的散点图在python和R中的非线性回归拟合方法

    对于样本数据的散点图形如函数y=ax2+bx+c的图像的数据, 在python中的拟合过程为: ##最小二乘法 import numpy as np import scipy as sp import ...

随机推荐

  1. JavaWeb 后端 <六> 之 EL & JSTL 学习笔记

    一.EL表达式(特别重要)

  2. H5读取本地文件操作

    H5读取本地文件操作 本文转自:转:http://hushicai.com/2014/03/29/html5-du-qu-ben-di-wen-jian.html感谢大神分享. 常见的语言比如php. ...

  3. 关于delete使用limit的一些注意事项

    在使用delete删除记录时,如果表里面存在多条相同的记录,但是此刻你只想删除一条记录,那么limit就派上了用场.但是使用limit的时候得注意: 如图,您如果想着删除第一个名字叫做张三的,如果你这 ...

  4. promise异步编程的原理

    一.起源 JavaScript中的异步由来已久,不论是定时函数,事件处理函数还是ajax异步加载都是异步编程的一种形式,我们现在以nodejs中异步读取文件为例来编写一个传统意义的异步函数: var ...

  5. [noip 2015]运输计划 [LCA][树链剖分]

    用了luogu上的题目描述 题目背景 公元 2044 年,人类进入了宇宙纪元. 题目描述 L 国有 n 个星球,还有 n-1 条双向航道,每条航道建立在两个星球之间,这 n-1 条航道连通了 L 国的 ...

  6. (转)Sublime Text中文乱码问题

    Sublime Text 2是一个非常不错的源代码及文本编辑器,但是不支持GB2312和GBK编码在很多情况下会非常麻烦.不过Sublime Package Control所以供的插件可以让Subli ...

  7. 【JAVASCRIPT】React学习- 杂七杂八

    摘要 记录 React 学习中的小细节 setState setState 有一定的时间延迟,如果需要保证 setState 之后执行某些动作,可以采用以下方法 this.setState({ vis ...

  8. ubuntu上安装nginx+mysql+php5-fpm(PHP5 - FastCGI Process Manager)

    题外话:由于近段时间测试环境ssh链路质量不大好,经常短线.故我把整个安装过程放到screen里去执行,以防止断线中断了安装过程.执行screen -S install,这样断线后,只要再执行scre ...

  9. Filter ,Interceptor,AOP

    一.Filter: Filter也称之为过滤器,它是Servlet技术中比较激动人心的技术,WEB开发人员通过Filter技术,对web服务器管理的所有web资源:例如Jsp, Servlet, 静态 ...

  10. 表达式求值(二叉树方法/C++语言描述)(四)

    代码清单 // binarytree.h #ifndef BINARYTREE_H #define BINARYTREE_H template <typename T> class Bin ...