您的位置:首页 > 编程语言 > C#

c#,委托,回调,事件,系列,一,

2008-06-03 22:55 337 查看
C#调用C++回调函数的问题

C++的回调函数中有一个参数是,是返回一个字符串,原则如下:
typedef void (*TDataEvent)(char *AData ,int ALen);
其中char *AData是从DLL中返回一个字符串,串的内存已经在DLL中分配了

下面中我在C#中定义的委托
public delegate void TDataEvent(Byte[] AData, int ALen);

下面是回调函数的设置代码:
Event = new clReceivelDllPoxy.TDataEvent(getDate);
ReceDllPoxy.AddServer(1024, Event, 2);
其中 Event是上面委托的实例,我定义成一个成员这样就不会被自己释放

下面是C#中回调函数的实现
public void getDate(byte[] AData, int ALen)
{
//发现每次回调是 AData只有一个字节
}

下面转载一个别人的代码,谢谢

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Reflection;
using System.Reflection.Emit;

namespace AppDllTest
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: