c# 调用 c++写的DLL



解决办法 安装 vcredist 运行库 或者用VC6.0编写DLL

Win32 dll
新建项目, Win32项目
Win32Project1.cpp
// Win32Project1.cpp : 定义 DLL 应用程序的导出函数。
//
#include "stdafx.h"
extern "C" __declspec(dllexportint add(int x,int y)
{
    return x + y;
}
 



创建c#程序  将编译好的程序 放到 c#的RELEASE目录下

        [System.Runtime.InteropServices.DllImport("Win32Project1.dll")]
        private static extern int add(int xint y);
        private void button1_Click(object senderEventArgs e)
        {
            MessageBox.Show(add(9, 9).ToString());
        }






posted @ 2014-06-15 08:32  XE2011  阅读(192)  评论(0编辑  收藏  举报