Doubts using P/Invoking

  • Thread starter Anderson Takemitsu Kubota
  • Start date
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
 
A

Anderson Takemitsu Kubota

Can you tell me where it is?
I searched for IOCTL_PROCESSOR_INFORMATION, but I have found nothing.


Alex Feinman said:
It's all already done in the OpenNETCF library. We did it (and provided in
the source format) so that the others would be spared the guesswork.

http://www.opennetcf.org/winapi.asp


Anderson Takemitsu Kubota said:
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
 
C

Chris Tacke, eMVP

pkfuncs.h (C:\WINCE420\PUBLIC\COMMON\OAK\INC) says:

#define IOCTL_PROCESSOR_INFORMATION CTL_CODE(FILE_DEVICE_HAL, 25,
METHOD_BUFFERED, FILE_ANY_ACCESS)

winoctl.h (C:\WINCE420\PUBLIC\COMMON\SDK\INC) says:
#define FILE_ANY_ACCESS 0
#define METHOD_BUFFERED 0

#define CTL_CODE( DeviceType, Function, Method, Access ) ( \
((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
)

#define FILE_DEVICE_HAL 0x00000101


--
Chris Tacke, eMVP
Advisory Board Member
www.OpenNETCF.org
---
Windows CE Product Manager
Applied Data Systems
www.applieddata.net

Anderson Takemitsu Kubota said:
Can you tell me where it is?
I searched for IOCTL_PROCESSOR_INFORMATION, but I have found nothing.


Alex Feinman said:
It's all already done in the OpenNETCF library. We did it (and provided in
the source format) so that the others would be spared the guesswork.

http://www.opennetcf.org/winapi.asp


Anderson Takemitsu Kubota said:
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
 
Top