export extern (C) void Fun Error
"拖狗散步"
djj at shumtn.com
Thu Apr 26 06:01:43 PDT 2012
export c callback fun:
alias void function(int id) ConnectedCallBack;
alias void function(int id, void* data, int len) ReadCallBack;
export extern (C) void AddListenersss( ConnectedCallBack
connectedCallBack=null, ReadCallBack readCallBack=null )
{
int id = 0;
int len = 0;
version(Windows)
{
while(true)
{
Thread.sleep( dur!("seconds")( 2 ) );
id++;
connectedCallBack(id);
len+=id;
Thread.sleep( dur!("seconds")( 1 ) );
readCallBack(id, null, len);
}
}
else
{
//server = new epoll();
}
}
And then use the exported dll called D and C, C #
In addition to the D outside the
Other returns are wrong values, such as C #:
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void OnConnectedCallBack(int id);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void OnReceivedCallBack(int sock, IntPtr pData,
int len);
[DllImport("ShuNetTcp.dll",EntryPoint = "AddListenersss", CharSet
= CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
public static extern void AddListenersss(OnConnectedCallBack
connectedCallback, OnReceivedCallBack readCallBack );
using:
m_onConnected = new NetServer.OnConnectedCallBack(OnConnected);
m_onReceived = new NetServer.OnReceivedCallBack(OnRead);
NetServer.AddListenersss( m_onConnected, m_onReceived );
call fun:
private void OnConnected(int id)
{
Console.WriteLine ("连接完成 Id=>" + id.ToString());
}
private void OnRead(int id, IntPtr pdata, int len)
{
}
Received id and len are wrong! :(
Gurus to help me!!!!!!!!!!!!
More information about the Digitalmars-d
mailing list