如果我将本机函数的签名转换为带有指向结构的指针的C#,我将其定义为ref
,并将转换后的struct
作为类型。
如果指向struct的指针不是函数参数而是其他结构成员,那么正确的方法是什么?
我真的需要在这里做Marshal.AllocHGlobal
所有的事情吗?
只需要在p / invoke调用期间从本机代码访问该对象。
[StructLayout(LayoutKind.Sequential)]
public struct WINTRUST_DATA
{
public uint cbStruct;
public IntPtr pPolicyCallbackData;
public IntPtr pSIPClientData;
public uint dwUIChoice;
public uint fdwRevocationChecks;
public uint dwUnionChoice;
// Pointer to WINTRUST_FILE_INFO:
// public IntPtr pFile;
// public WINTRUST_FILE_INFO pFile;
// ?
public uint dwStateAction;
public IntPtr hWVTStateData;
public IntPtr pwszURLReference;
public uint dwProvFlags;
public uint dwUIContext;
}
[StructLayout(LayoutKind.Sequential)]
public struct WINTRUST_FILE_INFO
{
public uint cbStruct;
[MarshalAs(UnmanagedType.LPWStr)] public string pcwszFilePath;
public IntPtr hFile;
public IntPtr pgKnownSubject;
}
[DllImport("wintrust.dll")]
public static extern int WinVerifyTrust(IntPtr hWnd, ref Guid pgActionID, ref WINTRUST_DATA pWVTData);