【问题标题】:How to use RAPI.Invoke to call device winapi method from Desktop app如何使用 RAPI.Invoke 从桌面应用程序调用设备 winapi 方法
【发布时间】:2015-10-28 04:20:32
【问题描述】:

我需要从桌面应用程序中获取设备 ID,其中设备是基于 Windows CE 5.0 的手持终端,它连接到 PC。

从设备内的应用程序中获取这些信息很容易,例如,我可以使用任何GetDeviceUniqueIDKernelIoControl 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


    【解决方案1】:

    我找到了答案here。简而言之;没有直接的方法,我需要用 C 创建一个 Win32 dll,在其中调用 WINAPI 并将其部署到 \Windows 文件夹。之后我可以将它与RAPI.Invoke() 一起使用。

    另外,this 是包含实现的文章的链接。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-23
      • 2011-11-20
      • 1970-01-01
      • 1970-01-01
      • 2010-10-06
      • 2021-06-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多