// in C#
+ using System;
+ using System.Collections.Generic;
+ using System.ComponentModel;
+ using System.Data;
+ using System.Drawing;
+ using System.Linq;
+ using System.Text;
+ using System.Windows.Forms;
+
+ using System.Runtime.InteropServices;
+
+ namespace WindowsFormsApplication3
+ {
+ public partial class Form1 : Form
+ {
+ public Form1()
+ {
+ InitializeComponent();
+ }
+ [DllImport("mycpp.dll", CallingConvention = CallingConvention.Cdecl)]
+ public static extern int add(int x, int y);
+
+ private void button1_Click(object sender, EventArgs e)
+ {
+ textBox3.Text = add( Convert.ToInt32(textBox1.Text) ,
+ Convert.ToInt32(textBox2.Text) ).ToString();
+ }
+ }
+ }
// in C++
+ #include <stdio.h>
+
+ extern "C" __declspec(dllexport) int add(int,int);
+
+ int __declspec(dllexport) add(int x,int y)
+ {
+ return x+y;
+ }
沒有留言:
張貼留言