【发布时间】:2019-12-13 01:37:40
【问题描述】:
我使用 C 编写了一个函数并将其构建到一个 DLL 文件中。 然后从 C# 中,我像这个示例一样从 Dll 调用我的函数。 https://blogs.msdn.microsoft.com/jonathanswift/2006/10/03/dynamically-calling-an-unmanaged-dll-from-net-c/ 有这样的功能: 在 C 中:
typedef struct {
DWORD Old;
}STRUCT_SON;
typedef struct {
DWORD NumberOfGirl;
STRUCT_SON SonList[8];
}STRUCT_PARENT;
int getStructExample(STRUCT_PARENT* x_lstExample, DWORD* x_dwSum)
{
....
}
在 C# 中:
private delegate int getStructExampleDelegate(out ?????,out int iSum);
IntPtr pAddressOfFunctionToCall = NativeMethods.GetProcAddress(pDll,
"getStructExample");
getStructExampleDelegate getStructExample =
(getStructExampleDelegate)Marshal.GetDelegateForFunctionPointer(
pAddressOfFunctionToCall,typeof(getStructExampleDelegate));
int iSum;
int theResult = getStructExample(out ??????, out iSum);
所以我的问题是如何获取结构数据类型? 也许使用 Marshal.PtrToStructure。但是什么是“??????”获取数组 STRUCT_SON。 C# Calling C++ DLL Function which returns a struct 我像这个例子一样使用来获取 x_dwSum,但不知道如何获取该结构。
【问题讨论】: