日期:2014-05-18 浏览次数:20896 次
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(); } private void button1_Click(object sender, EventArgs e) { int ret= mycl.test(testarr.arr); for (int k = 0; k < testarr.arr.Length; ++k) { textBox1.Text = textBox1.Text + testarr.arr[k].ToString(); } public class mycl { [DllImport("testdll.dll")] public static extern int test(int[] arr); //testdll为c++写的win32 dll,里面有个test函数,对传入的数组进行初始化 } public class testarr { public unsafe static int[] arr = new int[100]; } }
unsafe struct testarr { public fixed int arr[32]; //请留意括号'[]'的位置 }