110,567
社区成员
发帖
与我相关
我的任务
分享
void Connecter(int ServerPort,void(* pF)(char* buf,char* ClientIP,int ClientPort));
public class RefComm
{
[DllImport("MyServerDLL.dll",
EntryPoint = "Connecter",
CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void Connecter(int ServerPort,void(* pF)(char* buf,char* ClientIP,int ClientPort));
}
public delegate void FunctionDelegate(ref string buf, ref string ClientIP, int ClientPort);
IntPtr P=Marshal.AllocHGlobal(1024 * 1024 * 10);
Marshal.StructureToPtr(new FunctionDelegate(Callback).Target, P, true);
Connecter(1000, P);
//。。。
// 最后释放内存
Marshal.FreeHGlobal(P);
public class RefComm
{
[DllImport("MyServerDLL.dll",
EntryPoint = "Connecter",
CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void Connecter(int ServerPort,void(* pF)(char* buf,char* ClientIP,int ClientPort));
}
f(char* buf,char* ClientIP,int ClientPort);
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 WindowsApplication67
{
public partial class Form1 : Form
{
[DllImport("MyServerDLL.dll")]
public static extern void Connecter(int ServerPort, IntPtr P);
public delegate void FunctionDelegate(string buf, string ClientIP, int ClientPort);
public Form1()
{
IntPtr P = new IntPtr();
Marshal.StructureToPtr(new FunctionDelegate(Callback).Target, P, true);
Connecter(1000, P);
}
void Callback(string buf, string ClientIP, int ClientPort)
{
// ...
}
}
}
public delegate void FunctionDelegate(byte buf, byte ClientIP, int ClientPort);
public static extern void Connecter(int ServerPort, FunctionDelegate fP);
[DllImport("MyServerDLL.dll")]
public static extern void Connecter(int ServerPort, FunctionDelegate fP);
public delegate void FunctionDelegate(string buf, string ClientIP, int ClientPort);
[DllImport("MyServerDLL.dll")]
public static extern void Connecter(int ServerPort, IntPtr P);
delegate void FunctionDelegate(string buf,string ClientIP,int ClientPort);
public static extern void Connecter(int ServerPort,FunctionDelegate fP);