C
Christian Stelte
Hi!
I need the serial number of a pda. The manufacturer send me a c sourcecode,
but I could not translate it at all to c#. Could anyone help?
Original source:
-------------------------------------------
#define IOCTL_CODE_HUW 0xc33
// HUW_IO-Control: further specification over sub- commands
#define HUW_IOCTL_KEY 0x6157
// key for detection of unacceptable IOCTL- calls
#define SUBCMD_LOAD_INDIVIDUAL_DATA 0x25
// read individual device infos
#define SUBCMD_GET_FLASH_NR 0x4e
// read flash- ID
#define HUW_IOCTL(Buffer, pReturnSize) KernelIoControl(IOCTL_CODE_HUW,
Buffer, sizeof(Buffer), Buffer, sizeof(Buffer), pReturnSize)
extern "C" BOOL KernelIoControl(DWORD dwIoControlCode, LPVOID lpInBuf, DWORD
nInBufSize, LPVOID lpOutBuf, DWORD nOutBufSize, LPDWORD lpBytesReturned);
INDIVIDUAL_GLOBALS individual_data;
typedef struct _INDIVIDUAL_GLOBALS
{
ULONG CheckSum;
UCHAR SerialNr[12]; // Serialnumber of the pda
} INDIVIDUAL_GLOBALS, *PINDIVIDUAL_GLOBALS;
//--- snip ---
int i;
TCHAR szSerialNr[32];
DWORD InBuf[6]; // for IOCTL-Funktion
//read the serial number:
InBuf[0] = HUW_IOCTL_KEY;
InBuf[1] = SUBCMD_LOAD_INDIVIDUAL_DATA;
InBuf[2] = (DWORD) &individual_data; // copy data int this structure
InBuf[3] = sizeof (individual_data);
if (HUW_IOCTL(InBuf, NULL) != TRUE) // Is this IOCTL not supported!
{
MessageBox(hWnd, L"Function not supported!", L"", MB_OK);
break;
}
for (i=0; i < 12; i++)
szSerialNr = (TCHAR)individual_data.SerialNr; // ascii -> wcstring
szSerialNr[12] = TEXT('\0'); // string termination
-------------------------------------------
And now my:
-------------------------------------------
private static UInt32 IOCTL_CODE_HUW = 0xc33;
private static UInt32 HUW_IOCTL_KEY = 0x6157;
private static UInt32 SUBCMD_LOAD_INDIVIDUAL_DATA = 0x25;
private static UInt32 SUBCMD_GET_FLASH_NR = 0x4e;
//#define HUW_IOCTL(Buffer, pReturnSize) KernelIoControl(IOCTL_CODE_HUW,
Buffer, sizeof(Buffer), Buffer, sizeof(Buffer), pReturnSize)
// I did now know if this is possible in c#. I use the function direct in
the if-statement below...
[DllImport("coredll.dll", SetLastError = true)]
private static extern bool KernelIoControl(
UInt32 dwIoControlCode,
IntPtr lpInBuf,
UInt32 nInBufSize,
IntPtr lpOutBuf,
UInt32 nOutBufSize,
ref UInt32 lpBytesReturned);
struct INDIVIDUAL_GLOBALS
{
UInt32 CheckSum;
byte[] SerialNr;
}
public static string GetDeviceID()
{
INDIVIDUAL_GLOBALS individual_data;
UInt32 i;
char[] szSerialNr = new char[32]; // char[] correct? I need a Ascii to Ansi
conversion, I suppose?
UInt32[] InBuf = new UInt32[6];
InBuf[0] = HUW_IOCTL_KEY;
InBuf[1] = SUBCMD_LOAD_INDIVIDUAL_DATA;
InBuf[2] = ?? // How do I create this pointer? (DWORD) &individual_data;
InBuf[3] = ?? // sizeof (individual_data) is unsafe code. And this struct
didn't have a .lenght() function.
if (!KernelIoControl(IOCTL_CODE_HUW, ???, (UInt32)InBuf.Length, ???,
(UInt32)InBuf.Length, ref i))
// The second and fourth parameter need a IntPtr. IntBuf[] is a UINT32[].
How do I create this pointer?
{
MessageBox.Show("Function not supported!");
return "Error";
}
// This will be the next problems: Convert Ascii to Ansi and achar-array to
astring
// I have not translated until now
//for (i=0; i < 12; i++)
//szSerialNr = (TCHAR)individual_data.SerialNr; // ascii -> wcstring
//
//szSerialNr[12] = TEXT('\0'); // string termination
//
}
-------------------------------------------
Please have a look at it!
Thanks!
Chris
I need the serial number of a pda. The manufacturer send me a c sourcecode,
but I could not translate it at all to c#. Could anyone help?
Original source:
-------------------------------------------
#define IOCTL_CODE_HUW 0xc33
// HUW_IO-Control: further specification over sub- commands
#define HUW_IOCTL_KEY 0x6157
// key for detection of unacceptable IOCTL- calls
#define SUBCMD_LOAD_INDIVIDUAL_DATA 0x25
// read individual device infos
#define SUBCMD_GET_FLASH_NR 0x4e
// read flash- ID
#define HUW_IOCTL(Buffer, pReturnSize) KernelIoControl(IOCTL_CODE_HUW,
Buffer, sizeof(Buffer), Buffer, sizeof(Buffer), pReturnSize)
extern "C" BOOL KernelIoControl(DWORD dwIoControlCode, LPVOID lpInBuf, DWORD
nInBufSize, LPVOID lpOutBuf, DWORD nOutBufSize, LPDWORD lpBytesReturned);
INDIVIDUAL_GLOBALS individual_data;
typedef struct _INDIVIDUAL_GLOBALS
{
ULONG CheckSum;
UCHAR SerialNr[12]; // Serialnumber of the pda
} INDIVIDUAL_GLOBALS, *PINDIVIDUAL_GLOBALS;
//--- snip ---
int i;
TCHAR szSerialNr[32];
DWORD InBuf[6]; // for IOCTL-Funktion
//read the serial number:
InBuf[0] = HUW_IOCTL_KEY;
InBuf[1] = SUBCMD_LOAD_INDIVIDUAL_DATA;
InBuf[2] = (DWORD) &individual_data; // copy data int this structure
InBuf[3] = sizeof (individual_data);
if (HUW_IOCTL(InBuf, NULL) != TRUE) // Is this IOCTL not supported!
{
MessageBox(hWnd, L"Function not supported!", L"", MB_OK);
break;
}
for (i=0; i < 12; i++)
szSerialNr = (TCHAR)individual_data.SerialNr; // ascii -> wcstring
szSerialNr[12] = TEXT('\0'); // string termination
-------------------------------------------
And now my:
-------------------------------------------
private static UInt32 IOCTL_CODE_HUW = 0xc33;
private static UInt32 HUW_IOCTL_KEY = 0x6157;
private static UInt32 SUBCMD_LOAD_INDIVIDUAL_DATA = 0x25;
private static UInt32 SUBCMD_GET_FLASH_NR = 0x4e;
//#define HUW_IOCTL(Buffer, pReturnSize) KernelIoControl(IOCTL_CODE_HUW,
Buffer, sizeof(Buffer), Buffer, sizeof(Buffer), pReturnSize)
// I did now know if this is possible in c#. I use the function direct in
the if-statement below...
[DllImport("coredll.dll", SetLastError = true)]
private static extern bool KernelIoControl(
UInt32 dwIoControlCode,
IntPtr lpInBuf,
UInt32 nInBufSize,
IntPtr lpOutBuf,
UInt32 nOutBufSize,
ref UInt32 lpBytesReturned);
struct INDIVIDUAL_GLOBALS
{
UInt32 CheckSum;
byte[] SerialNr;
}
public static string GetDeviceID()
{
INDIVIDUAL_GLOBALS individual_data;
UInt32 i;
char[] szSerialNr = new char[32]; // char[] correct? I need a Ascii to Ansi
conversion, I suppose?
UInt32[] InBuf = new UInt32[6];
InBuf[0] = HUW_IOCTL_KEY;
InBuf[1] = SUBCMD_LOAD_INDIVIDUAL_DATA;
InBuf[2] = ?? // How do I create this pointer? (DWORD) &individual_data;
InBuf[3] = ?? // sizeof (individual_data) is unsafe code. And this struct
didn't have a .lenght() function.
if (!KernelIoControl(IOCTL_CODE_HUW, ???, (UInt32)InBuf.Length, ???,
(UInt32)InBuf.Length, ref i))
// The second and fourth parameter need a IntPtr. IntBuf[] is a UINT32[].
How do I create this pointer?
{
MessageBox.Show("Function not supported!");
return "Error";
}
// This will be the next problems: Convert Ascii to Ansi and achar-array to
astring
// I have not translated until now
//for (i=0; i < 12; i++)
//szSerialNr = (TCHAR)individual_data.SerialNr; // ascii -> wcstring
//
//szSerialNr[12] = TEXT('\0'); // string termination
//
}
-------------------------------------------
Please have a look at it!
Thanks!
Chris