【发布时间】:2015-10-28 04:20:32
【问题描述】:
我需要从桌面应用程序中获取设备 ID,其中设备是基于 Windows CE 5.0 的手持终端,它连接到 PC。
从设备内的应用程序中获取这些信息很容易,例如,我可以使用任何GetDeviceUniqueID 或KernelIoControl WinApi 方法:
[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;
}
但我需要从桌面应用程序中获取它。
Windows Mobile 5.X SDK 中有一个示例可以从桌面应用程序获取此 ID。由于我使用的是 Windows CE,因此该示例没有提供 ID(适用于 windows mobile)。
我相信可能使用 RAPI.Invoke() 方法(或 Opennetcf RAPI)从桌面应用程序中使用所述方法。但我不知道如何将 RAPI.Invoke 与多参数 WinApi 方法一起使用,例如获取设备唯一标识。
我有一个示例代码,还包括 WinApi 方法的 C# 签名作为注释:
//[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
}
还有一个类似的问题here,但没有提供任何解决方案。
【问题讨论】:
标签: c# winapi windows-mobile windows-ce rapi