Pinvoke Signature for SP_DRVINFO_DETAIL_DATA,...

K

Kerem Gümrükcü

Hi,

how would you translate this to C#:

typedef struct _SP_DRVINFO_DETAIL_DATA_W {
DWORD cbSize;
FILETIME InfDate;
DWORD CompatIDsOffset;
DWORD CompatIDsLength;
ULONG_PTR Reserved;
WCHAR SectionName[LINE_LEN];
WCHAR InfFileName[MAX_PATH];
WCHAR DrvDescription[LINE_LEN];
WCHAR HardwareID[ANYSIZE_ARRAY];
}

sizeof in C gives me 1570 bytes

The important part is that the cbSize
Member must be set before it will be
used. The problem is the ANYSIZE_ARRAY
Member with name "HardwareId" since
when i do it that way:

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct SP_DRVINFO_DETAIL_DATA
{
public int cbSize;
public System.Runtime.InteropServices.ComTypes.FILETIME InfDate;
public int CompatIDsOffset;
public int CompatIDsLength;
public UIntPtr Reserved;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string SectionName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string InfFileName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string DrvDescription;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
public string HardwareID;
}

a call to:

Buffer.cbSize =
Marshal.SizeOf(typeof(SetupApiClass.SP_DRVINFO_DETAIL_DATA));

fails with SystemArgumentException and the runtime tells me, that it cannot
determine the right size for the buffer by using that way. So, what is the
right
way,...except using raw IntPtr Marshal.AllocHGlobal() Memory Buffers?

Is the Translation of the ANYSIZE_ARRAY ok so far?

Thanks in Advance,...

regards

Kerem
 
G

Giovanni Dicanio

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct SP_DRVINFO_DETAIL_DATA
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
public string HardwareID;
Is the Translation of the ANYSIZE_ARRAY ok so far?

I'm not sure, but have you tried the following?

[MarshalAs(UnmanagedType.ByValArray)]
public char[] HardwareID;

Giovanni
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top