digitalmars.D - export extern (C) void Fun Error
- =?UTF-8?B?IuaLlueLl+aVo+atpSI=?= (51/51) Apr 26 2012 export c callback fun:
- =?UTF-8?B?IuaLlueLl+aVo+atpSI=?= (1/1) Apr 26 2012 O God, no one answered...
- Trass3r (1/4) Apr 26 2012 add extern(C) to be safe
- =?UTF-8?B?IuaLlueLl+aVo+atpSI=?= (2/7) Apr 27 2012 Thank, Trass3r! Finally correct, why have to export these two?
- Matt Peterson (6/14) Apr 27 2012 You specified the C calling convention with
- =?UTF-8?B?IuaLlueLl+aVo+atpSI=?= (2/19) Apr 28 2012 The original so thank you
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();
}
}
In addition to the D outside the
[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!!!!!!!!!!!!
Apr 26 2012
export c callback fun: alias void function(int id) ConnectedCallBack; alias void function(int id, void* data, int len) ReadCallBack;add extern(C) to be safe
Apr 26 2012
On Friday, 27 April 2012 at 01:21:56 UTC, Trass3r wrote:Thank, Trass3r! Finally correct, why have to export these two?export c callback fun: alias void function(int id) ConnectedCallBack; alias void function(int id, void* data, int len) ReadCallBack;add extern(C) to be safe
Apr 27 2012
On Friday, 27 April 2012 at 13:02:56 UTC, 拖狗散步 wrote:On Friday, 27 April 2012 at 01:21:56 UTC, Trass3r wrote:You specified the C calling convention with UnmanagedFunctionPointer(CallingConvention.Cdecl), and extern(C) means use the C calling convention. Otherwise they'll be expecting a function using the D calling convention, which is incompatible.Thank, Trass3r! Finally correct, why have to export these two?export c callback fun: alias void function(int id) ConnectedCallBack; alias void function(int id, void* data, int len) ReadCallBack;add extern(C) to be safe
Apr 27 2012
On Friday, 27 April 2012 at 15:04:48 UTC, Matt Peterson wrote:On Friday, 27 April 2012 at 13:02:56 UTC, 拖狗散步 wrote:The original so thank youOn Friday, 27 April 2012 at 01:21:56 UTC, Trass3r wrote:You specified the C calling convention with UnmanagedFunctionPointer(CallingConvention.Cdecl), and extern(C) means use the C calling convention. Otherwise they'll be expecting a function using the D calling convention, which is incompatible.Thank, Trass3r! Finally correct, why have to export these two?export c callback fun: alias void function(int id) ConnectedCallBack; alias void function(int id, void* data, int len) ReadCallBack;add extern(C) to be safe
Apr 28 2012









=?UTF-8?B?IuaLlueLl+aVo+atpSI=?= <djj shumtn.com> 