2016年7月27日 星期三

自動產生Deligate

今天在測試加入/刪除call back func的時候用到 HookHandlerDelegate = new MIL_GRA_HOOK_FUNCTION_PTR(drawRenewHook); MgraHookFunction(graphicListId, MIL.M_GRAPHIC_LIST_MODIFIED, HookHandlerDelegate , M_NULL); vs MIL.MgraHookFunction(graphicListId, MIL.M_GRAPHIC_LIST_MODIFIED, drawRenewHook, M_NULL); 兩個都可以用,but下面那種方式會有無法取消hook的問題

MIL.MgraHookFunction(graphicListId, MIL.M_GRAPHIC_LIST_MODIFIED + MIL.M_UNHOOK, drawRenewHook, M_NULL); 會出現找不到該hool的錯誤訊息 MgraHookFunction 的簽名是 public static void MgraHookFunction(MIL_ID GraListId, MIL_INT HookType, MIL_GRA_HOOK_FUNCTION_PTR HookHandlerPtr, IntPtr UserDataPtr); 其中MIL_GRA_HOOK_FUNCTION_PTR是 public delegate MIL_INT MIL_GRA_HOOK_FUNCTION_PTR(MIL_INT HookType, MIL_ID EventId, IntPtr UserDataPtr); drawRenewHook是一個function應該是跟MIL_GRA_HOOK_FUNCTION_PTR型態不合,但是應該是會自動轉換 測試 MIL_GRA_HOOK_FUNCTION_PTR a1 = drawRenewHook; MIL_GRA_HOOK_FUNCTION_PTR a2 = drawRenewHook; a1==a2; 會傳回true!? MIL_GRA_HOOK_FUNCTION_PTR a3 = new MIL_GRA_HOOK_FUNCTION_PTR( drawRenewHook); MIL_GRA_HOOK_FUNCTION_PTR a4 = new MIL_GRA_HOOK_FUNCTION_PTR( drawRenewHook); a3==a4; 會傳回true!? 把上面都加入List查詢也都得到true... 到底mil是怎麼實作造成MIL.MgraHookFunction(graphicListId, MIL.M_GRAPHIC_LIST_MODIFIED + MIL.M_UNHOOK, drawRenewHook, M_NULL);找不到在MIL.MgraHookFunction(graphicListId, MIL.M_GRAPHIC_LIST_MODIFIED, drawRenewHook, M_NULL);加入的東西呢?..

沒有留言:

張貼留言