【发布时间】:2009-11-18 04:04:29
【问题描述】:
我有一个用 C++ 编写的 .dll,其函数定义如下:
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
这个函数的用法,如上图所示:如果level = 1,会这样调用:
EE_CognitivSetCurrentLevel(userId,1,level1Action);
如果级别 = 2,则:
EE_CognitivSetCurrentLevel(userId,2,level1Action,level2Action);
等等……
如何在 C# 中调用此函数?
非常感谢!
【问题讨论】:
-
C++
EE_CognitivSetCurrentLevel()函数是使用默认参数编写的,还是采用可变数量参数的__cdecl函数?正确的做法会有所不同。 -
很遗憾我没有这个dll的原始源代码。我怎么知道它是使用默认参数编写的还是 _cdecl 函数?
-
如果默认不使用相同的约定,你会得到错误的参数。如果您想明确设置它,请将其添加到我的答案中的 DllImport 参数中:CallingConvention=CallingConvention.Cdecl。如果需要,请查看 msdn.microsoft.com/en-us/library/… 了解其他选项。