I want to call via c#/PInvoke the GetLogicalProcessorInformation
function, but I'm stuck with SYSTEM_LOGICAL_PROCESSOR_INFORMATION
struct and CACHE_DESCRIPTOR
struct.
How should I define these structs for correct usage?
Main problems:
1. SYSTEM_LOGICAL_PROCESSOR_INFORMATION
has union in its definition
2. SYSTEM_LOGICAL_PROCESSOR_INFORMATION
has ULONGLONG
in its definition
3. CACHE_DESCRIPTOR
has WORD
and DWORD
in its definition.
Can you help me with these structures?
A
DWORD
is auint
andWORD
is aushort
.A
union
is a structure with aExplicit
layout andFieldOffset
.A
ULONGLONG
is aUInt64
. It is being to align the structure to 8 byte boundary (24 bytes). As David pointed out in the comments, it is required and for some reason it was missing from the Microsoft Interop library.Update: Added missing structures and link to the Windows Interop Library from Microsoft Research.
Source: WindowsInteropLib/Kernel32.cs
Updated: fixed the structure marshalling which has to be done manually.
This is quite a messy P/invoke. Even when you have the structs and the union defined, it's non-trivial to call the function because you have to marshal the structures manually.