[英]How to convert this C type to a c# type
I have a type CK_NOTIFY in C++ defined as follows: 我在C ++中定义了CK_NOTIFY类型,如下所示:
typedef uint ( * CK_NOTIFY)(
uint hSession,
uint event,
void* pApplication
);
I need to redefine this type in C# because I need to use it as an argument for a pinvoke function. 我需要在C#中重新定义此类型,因为我需要将其用作pinvoke函数的参数。 What is it exactly?
究竟是什么? A structure?
一个结构? Or a function pointer?
还是函数指针?
It would be a delegate
. 那将是一名
delegate
。 Your "C type" is describing a function. 您的“ C类型”正在描述一个功能。
The function returns a uint
and takes 2 uints
and a void*
. 该函数返回一个
uint
并采取2周uints
和void*
。
So your delegate could look like: 因此您的代表看起来像:
Func<uint, uint, object, uint>
How you want to handle the void*
is up to you... 您要如何处理
void*
取决于您...
如果需要进行互操作(即,将其传递到非托管DLL),则需要这样的委托声明:
public delegate uint CK_NOTIFY(uint hSession, uint @event, System.IntPtr pApplication);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.