我具有.dll用C++編寫像這樣定義的函數:PInvoke的與「陌生」功能
EDK_API int EE_CognitivSetCurrentLevel (unsigned int userId,
EE_CognitivLevel_t level,
EE_CognitivAction_t level1Action,
EE_CognitivAction_t level2Action,
EE_CognitivAction_t level3Action,
EE_CognitivAction_t level4Action
)
Set the current Cognitiv level and corresponding action types.
Parameters:
userId - user ID
level - current level (min: 1, max: 4)
level1Action - action type in level 1
level2Action - action type in level 2
level3Action - action type in level 3
level4Action - action type in level 4
此功能的使用,因爲你可以看到上面:如果電平= 1,這是會這樣調用:
EE_CognitivSetCurrentLevel(userId,1,level1Action);
如果級別= 2,則:
EE_CognitivSetCurrentLevel(userId,2,level1Action,level2Action);
等等...
如何在C#中調用此函數?
非常感謝!
C++'EE_CognitivSetCurrentLevel()'函數是使用默認參數編寫的,還是它是一個'__cdecl'函數,它可以接受可變數量的參數?正確的做法會因此而有所不同。 – 2009-11-18 06:10:35
不幸的是,我沒有dll的原始源代碼。我怎麼知道它是使用默認參數編寫的,還是它是* _cdecl *函數? – Vimvq1987 2009-11-19 07:48:56
如果默認值不使用相同的約定,則會得到錯誤的參數。如果你想明確地設置它,在我的答案中添加這個DllImport參數:CallingConvention = CallingConvention.Cdecl。如果需要,請查看http://msdn.microsoft.com/zh-CN/library/system.runtime.interopservices.callingconvention.aspx以獲取其他選項。 – Gonzalo 2009-11-20 03:30:55