I need to get Device Id from a desktop application, where Device is a Windows CE 5.0 based handheld terminal and it is connected to PC.
Getting this information from an application within the device is easy, I can use any of GetDeviceUniqueID or KernelIoControl WinApi methods for example:
[DllImport("coredll.dll")]
private extern static int GetDeviceUniqueID([In, Out] byte[] appdata,
int cbApplictionData,
int dwDeviceIDVersion,
[In, Out] byte[] deviceIDOuput,
out uint pcbDeviceIDOutput);
public byte[] GetDeviceID(string AppString)
{
// Call the GetDeviceUniqueID
byte[] AppData = Encoding.Unicode.GetBytes(AppString);
int appDataSize = AppData.Length;
byte[] DeviceOutput = new byte[20];
uint SizeOut = 20;
GetDeviceUniqueID(AppData, appDataSize, 1, DeviceOutput, out SizeOut);
return DeviceOutput;
}
But I need to get this from Desktop application.
There is a sample within Windows Mobile 5.X SDK to get this ID from Desktop app. Since I am using Windows CE that sample does not give an ID (It's for windows mobile).
I believe it is possible to use said method from desktop app using RAPI.Invoke() method (Or Opennetcf RAPI). But I can't figure how to use RAPI.Invoke with multi-parameter WinApi method e.g. GetDeviceUniqueID .
I have a sample code, also included C# signature of WinApi method as comment:
//[DllImport("coredll.dll")]
//private extern static int GetDeviceUniqueID([In, Out] byte[] appdata,
// int cbApplictionData,
// int dwDeviceIDVersion,
// [In, Out] byte[] deviceIDOuput,
// out uint pcbDeviceIDOutput);
private void buttonGetDeviceID_Click(object sender, RoutedEventArgs e)
{
// RAPI
RAPI rapi = new RAPI();
rapi.Connect(true);
// How do I pass several parameters inside a byte[] ?
rapi.Invoke(@"\Windows\coredll.dll", "GetDeviceUniqueID", inputData, out outputData);
//Process outputData
}
Also there is a similar question here but does not provide any solution.
I found the answer here. In a nutshell; There is no direct way, I need to create a Win32 dll with C where call to WINAPI will be made and deploy it to \Windows folder. After that I can use it with
RAPI.Invoke()
.Also this is the link to article containing implementation.