我具有.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