惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Visual Studio Blog
A
About on SuperTechFans
J
Java Code Geeks
G
Google Developers Blog
L
LangChain Blog
小众软件
小众软件
宝玉的分享
宝玉的分享
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
博客园 - 【当耐特】
IT之家
IT之家
F
Fortinet All Blogs
aimingoo的专栏
aimingoo的专栏
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
阮一峰的网络日志
阮一峰的网络日志
V
V2EX
博客园 - Franky
博客园_首页
雷峰网
雷峰网
Microsoft Security Blog
Microsoft Security Blog
Vercel News
Vercel News
B
Blog
月光博客
月光博客
酷 壳 – CoolShell
酷 壳 – CoolShell

博客园 - jasonM

真是郁闷,团队中居然出了这样的骗子!! C++反汇编揭秘1 – 一个简单C++程序反汇编解析 函数调用堆栈变化分析 - jasonM - 博客园 为什么要下断bpSend,原理分析。 做挂第一步:如何找基址(以热血传奇为例) 一步步学外挂(二).CALL的原理。 - jasonM - 博客园 开发企业直销软件需求分析 开发旺旺群发软件,难点及重要技术点分析(一) 正则表达式系列文章整理 群发软件开发原理分析 通俗解释socket(并附上注释Socket源代码) CMainFrame::PreCreateWindow这个函数执行了两次 一步步学破解-sdk用实例讲解GDI映射机制 一步步学破解-sdk用实例讲解GDI(含各个消息的调用时机) 一步步学破解-sdk进程间传递信息 一步步学破解-在已有的主窗口上创建按钮(三) 一步步学破解-windows消息循环原理实例总结(二) 一步步学破解-函数调用堆栈变化分析 (一) 老王最新壳试脱时遇到的问题,详细表述如下
.net调用vc++写的dll
jasonM · 2009-06-03 · via 博客园 - jasonM

1.vc做的win32的dll,其中dll2.cpp文件代码如下:

int add(int a,int b)
{

 return a+b+1;
}

int subtract(int a,int b)
{
 return a-b;
}

2.dll2.def代码如下:

LIBRARY dll2
EXPORTS
add
subtract

3.将dll2.lib和dll2.dll拷到c#当前目录下

4.建立测试用的.net程序,代码如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;   

namespace WindowsApplication1
{


    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {


        }

        private void button1_Click(object sender, EventArgs e)
        {
           int nindex=Name1.add(2,0);
        }
    }

    public class Name1
    {

        //导入dll

        [DllImport("dll2.dll", CallingConvention = CallingConvention.StdCall)]

        //声明接口函数

        public static extern int add(int a, int b);

    }
}