I am trying to write the C# equivalent to the following:
typedef struct BATT_ID
{
UINT8 nBattID[8];
} BATT_ID, *PBATT_ID;
HANDLE g_hDevice;
// Connect to the driver
g_hDevice = CreateFile(L"BAT1:", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
void GetBattID(PBATT_ID pBattId)
{
// ... snipped code to check g_hDevice is valid ...
DeviceIoControl(g_hDevice, SOMO650_PWR_GET_BATT_ID, NULL, 0, pBattId, sizeof(BATT_ID), dwByteReturn, NULL))
}
// once BATT_ID has been filled it can be formatted as follows
wsprintf(strInfo, TEXT("%02X:%02X:%02X:%02X:%02X:%02X"), BattID.nBattID[6], BattID.nBattID[5], BattID.nBattID[4], BattID.nBattID[3], BattID.nBattID[2], BattID.nBattID[1]);
The code is connecting to the power driver of a Windows Mobile device and attempting to retrieve the battery Id.
This is for the latest ROM version of the SoMo650 and Socket are only able to provide sample code in C.
I can successfully do everything (as best as I can tell) apart from calling DeviceIoControl as I don't know how to translate the BATT_ID structure into C#.
I'm guessing that as it's a structure and DeviceIoControl expects a pointer I shoould be looking at Marshal.PtrToStructure() but I have very little C experience and feel very out of my depth.
Any assitance would be greatly appreciated.