Re: [問題] Callback 函式 (C# 呼叫 C++ dll) (用 delegate)
用 Delegate 的寫法
我寫到這樣 還是不會出現 haha
第一次接觸 應該有錯待改
請大家不吝指教 謝謝 <(_ _)>
dll 說明
 ̄ ̄ ̄ ̄
int __stdcall SKQuoteLib_AttachConnectionCallBack( [in]long lCallBack )
// lCallBack 帶入 Call back 的函式位址。當狀況發生時即可呼叫此函式進行處理
// 函式的宣告必須符合以下格式:
// typedef void ( __stdcall* FOnNotifyConnection)( int nKind, int nCode )
C# 部份
 ̄ ̄ ̄ ̄
// delegate
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
delegate void FOnNotifyConnection( int nKind, int nCode );
// dll,參數部份 到底該怎樣才能與 C++ 的 long 相容呢?
[DllImport("SKQuoteLib.dll")]
extern static int SKQuoteLib_AttachConnectionCallBack(
[MarshalAs(UnmanagedType.FunctionPtr)]
FOnNotifyConnection Delegate_AttachConnection );
// main
static void Main(string[] args)
{
FOnNotifyConnection Delegate_AttachConnection
= new FOnNotifyConnection( CBFunc_AttachConnection );
SKQuoteLib_AttachConnectionCallBack( Delegate_AttachConnection );
}
// 還沒辦法進到這個函式
static void CBFunc_AttachConnection( int nKind, int nCode )
{
Console.WriteLine("haha");
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.32.91.117
推
09/16 01:39, , 1F
09/16 01:39, 1F
→
09/16 09:08, , 2F
09/16 09:08, 2F
推
09/16 19:22, , 3F
09/16 19:22, 3F
→
09/16 19:22, , 4F
09/16 19:22, 4F
→
09/16 23:30, , 5F
09/16 23:30, 5F