调用vc++的DLL例子代码

C# 2022-03-08 15:25:37

调用vc++的DLL例子代码本实例在开发中有用的可以参考。
using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.Runtime.InteropServices;

namespace CxUseDll
{
public delegate void cb_func(int a);

class Cx
{


[DllImport("diaCallBackDll.dll")]
public static extern void show();

[DllImport("diaCallBackDll.dll", CallingConvention = CallingConvention.StdCall)]
public static extern int add_CallBack_test(int a, int b, cb_func f);

public static void cb_funcc(int re)
{
Console.WriteLine("result=[{0}]", re);

return;
}

static void Main(string[] args)
{
//show();

int i = add_CallBack_test(7, 2, cb_funcc);

Console.Read();
}
}
}