[問題] C# 傳function pointer 給c++ dll

看板C_and_CPP作者 (小飄)時間13年前 (2012/05/14 18:21), 編輯推噓1(101)
留言2則, 2人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) VC 2008 問題(Question): 請問如果想要從 C# 傳一個 callback function 給 C++ dll 讓 C++ 可以call 回 C# 這樣該怎麼做呢?? 我試了很久一直都有問題 煩請有經驗得大大幫忙 謝謝 CODE: C# 層寫法 宣告: public delegate void sizeChanged(int width, int height); 定義: public void OnSizeChanged(int width, int height) { } 使用: cpp_dll.setSizeChangedCB( OnSizeChanged ); C++ 層寫法 public ref class NativeDecoder { public: void setSizeChangedCB(void (*cb)(int,int)); } 錯誤結果(Wrong Output): 'setSizeChangedCB' is not supported by the language 請問是我哪裡寫錯了嗎?? 煩請指點 謝謝回覆 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 60.248.131.23 ※ 編輯: tocute 來自: 60.248.131.23 (05/14 18:24) ※ 編輯: tocute 來自: 60.248.131.23 (05/14 18:24)

05/14 19:31, , 1F
你是用COM dll 嗎
05/14 19:31, 1F

05/14 20:28, , 2F
NativeDecoder都用ref class了,怎麼不直接用delegate?
05/14 20:28, 2F
文章代碼(AID): #1FiDp7n8 (C_and_CPP)