Thread overview |
---|
April 26, 2012 export extern (C) void Fun Error | ||||
---|---|---|---|---|
| ||||
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!!!!!!!!!!!! |
April 27, 2012 Re: export extern (C) void Fun Error | ||||
---|---|---|---|---|
| ||||
Posted in reply to 拖狗散步 | O God, no one answered... |
April 27, 2012 Re: export extern (C) void Fun Error | ||||
---|---|---|---|---|
| ||||
Posted in reply to 拖狗散步 | > 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
|
April 27, 2012 Re: export extern (C) void Fun Error | ||||
---|---|---|---|---|
| ||||
Posted in reply to Trass3r | On Friday, 27 April 2012 at 01:21:56 UTC, Trass3r wrote:
>> 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
Thank, Trass3r! Finally correct, why have to export these two?
|
April 27, 2012 Re: export extern (C) void Fun Error | ||||
---|---|---|---|---|
| ||||
Posted in reply to 拖狗散步 | On Friday, 27 April 2012 at 13:02:56 UTC, 拖狗散步 wrote: > On Friday, 27 April 2012 at 01:21:56 UTC, Trass3r wrote: >>> 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 > > > Thank, Trass3r! Finally correct, why have to export these two? 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. |
April 28, 2012 Re: export extern (C) void Fun Error | ||||
---|---|---|---|---|
| ||||
Posted in reply to Matt Peterson | On Friday, 27 April 2012 at 15:04:48 UTC, Matt Peterson wrote:
> On Friday, 27 April 2012 at 13:02:56 UTC, 拖狗散步 wrote:
>> On Friday, 27 April 2012 at 01:21:56 UTC, Trass3r wrote:
>>>> 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
>>
>>
>> Thank, Trass3r! Finally correct, why have to export these two?
>
> 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.
The original so thank you
|
Copyright © 1999-2021 by the D Language Foundation