【发布时间】:2013-09-29 02:22:18
【问题描述】:
我可以DllImport常用函数,但是无法导入这种类型,下面是DLL头文件。
typedef struct
{
VOID (* API_GetUID)(CHAR *pData, DWORD DataLen);
DWORD (* API_GetChipType)();
} API_FUNCTION_STRUCT, *API_FUNCTION_STRUCT;
extern VOID WINAPI GetAPIObject(API_FUNCTION_STRUCT *pApiFunc);
我无法在 C# 中编写正确的结构。
public struct test
{
IntPtr API_GetUID(IntPtr pData, int DataLen);
IntPtr API_GetChipType();
}
[DllImport(@"GDevice.dll")]
public static extern void GetAPIObject(ref test test_a);
更新:
public struct test
{
delegate void API_GetUID(IntPtr pData, int DataLen);
delegate void API_GetChipType();
}
【问题讨论】:
-
我可以导入一些没有指针的函数,我想我应该用c#写一个struct,但我不知道如何处理指针
-
@igelineau ,我仍然无法正常工作。请您帮忙。
-
这到底是怎么失败的?您是否尝试过使用 IntPtr 作为方法参数而不是 ref?
-
您的
struct需要包含某种形式的函数指针,而不是方法。具有适当封送注释的委托可能会起作用。 -
@CodesInChaos 谢谢,我已经更新了内容,我已经测试了委托方法,但我找不到调用它的方法。可以举个例子吗?