A
Anderson Takemitsu Kubota
Hi!
I need to P/Invoke the following function:
public struct PROCESSOR_INFO
{
public ushort wVersion;
public byte[] szProcessCore;
public ushort wCoreRevision;
public byte[] szProcessorName;
public ushort wProcessorRevision;
public byte[] szCatalogNumber;
public byte[] szVendor;
public uint dwInstructionSet;
public uint dwClockSpeed;
}
public unsafe string GetProcessorInfo()
{
Int32 OutputBufferSize, BytesReturned;
BytesReturned = 0;
PROCESSOR_INFO pi;
int dwPlatformInfoCmd;
dwPlatformInfoCmd = 0;
int* iPtr = &dwPlatformInfoCmd;
IntPtr iPtrCtlCode = (IntPtr)iPtr;
Int32 buffersize = sizeof(PROCESSOR_INFO);
bool retVal = KernelIoControl(IOCTL_PROCESSOR_INFORMATION,
iPtrCtlCode,
4,
pi,
buffersize,
ref BytesReturned);
string strReturn = "";
string strAux;
return Convert.ToString(pi.szProcessCore)+ " -
"+Convert.ToString(pi.szProcessorName);
}
But I am getting the error:
Cannot take the address or size of a variable of a managed type
(PROCESSOR_INFO)
I believe that this problem is happening because I have the byte[] with a
non fixed lenght.
How could I solve this problem?
Thank you.
Anderson T. Kubota
I need to P/Invoke the following function:
public struct PROCESSOR_INFO
{
public ushort wVersion;
public byte[] szProcessCore;
public ushort wCoreRevision;
public byte[] szProcessorName;
public ushort wProcessorRevision;
public byte[] szCatalogNumber;
public byte[] szVendor;
public uint dwInstructionSet;
public uint dwClockSpeed;
}
public unsafe string GetProcessorInfo()
{
Int32 OutputBufferSize, BytesReturned;
BytesReturned = 0;
PROCESSOR_INFO pi;
int dwPlatformInfoCmd;
dwPlatformInfoCmd = 0;
int* iPtr = &dwPlatformInfoCmd;
IntPtr iPtrCtlCode = (IntPtr)iPtr;
Int32 buffersize = sizeof(PROCESSOR_INFO);
bool retVal = KernelIoControl(IOCTL_PROCESSOR_INFORMATION,
iPtrCtlCode,
4,
pi,
buffersize,
ref BytesReturned);
string strReturn = "";
string strAux;
return Convert.ToString(pi.szProcessCore)+ " -
"+Convert.ToString(pi.szProcessorName);
}
But I am getting the error:
Cannot take the address or size of a variable of a managed type
(PROCESSOR_INFO)
I believe that this problem is happening because I have the byte[] with a
non fixed lenght.
How could I solve this problem?
Thank you.
Anderson T. Kubota