export extern (C) void Fun
ww21xx
2012-04-26
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(); } } 然后用导出的dll我分别在 D、C、C#中调用 除了D之外 其它返回都是错误的值,例如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 ); 调用: m_onConnected = new NetServer.OnConnectedCallBack(OnConnected); m_onReceived = new NetServer.OnReceivedCallBack(OnRead); NetServer.AddListenersss( m_onConnected, m_onReceived ); 回调函数: private void OnConnected(int id) { Console.WriteLine ("连接完成 Id=>" + id.ToString()); } private void OnRead(int id, IntPtr pdata, int len) { } 接收到的 id 和 len 都是错误的! 大师们帮下忙! 那里错了? 我整了一周了! |
|
非仙
2012-04-26
我这里还没装好D的环境没法编译代码 ...你编译一个简单的DLL我帮你调试下看看
|
|
ww21xx
2012-04-27
非仙 写道 我这里还没装好D的环境没法编译代码 ...你编译一个简单的DLL我帮你调试下看看
兄弟 QQ、邮箱? |
|
sleets
2012-04-27
extern (C) { alias void function(int id) ConnectedCallBack; alias void function(int id, void* data, int len) ReadCallBack; } |
|
非仙
2012-04-27
ww21xx 写道 非仙 写道 我这里还没装好D的环境没法编译代码 ...你编译一个简单的DLL我帮你调试下看看
兄弟 QQ、邮箱? lovovv$qq.com |
|
非仙
2012-04-27
sleets 写道 extern (C) { alias void function(int id) ConnectedCallBack; alias void function(int id, void* data, int len) ReadCallBack; } 这个用法估计是对的 |
|
ww21xx
2012-04-27
sleets 写道 extern (C) { alias void function(int id) ConnectedCallBack; alias void function(int id, void* data, int len) ReadCallBack; } 酷!!! 正确了,偷偷问下你在官方论坛上叫 Trass3r 么?另外怎么这两个也需要导出? |
|
非仙
2012-04-27
ww21xx 写道 sleets 写道 extern (C) { alias void function(int id) ConnectedCallBack; alias void function(int id, void* data, int len) ReadCallBack; } 酷!!! 正确了,偷偷问下你在官方论坛上叫 Trass3r 么?另外怎么这两个也需要导出? 不是导出吧? 这里是用来指定调用约定 |