项目简介
本项目是基于C++和RPC框架开发的Windows IoT Core设备管理桥接器,为开发者提供在本地对IoT设备进行配置与监控的能力。项目向外暴露适用于UWP和非UWP应用程序的API,方便各类应用进行设备管理操作。
项目的主要特性和功能
- 多应用类型支持:支持UWP应用使用WinRT API,非UWP应用可直接调用Rpc API进行设备管理。
- 服务式运行:
DMBridge
作为NTService以SYSTEM
账户运行,提供稳定的Rpc服务。 - API清晰定义:
DMBridgeInterface
明确规定了Rpc方法,便于不同组件调用。 - UWP组件化:
DMBridgeComponenet
作为WinRT/C++组件,可构建为NuGet包,方便UWP应用集成。
安装使用步骤
开发环境准备
确保安装Visual Studio 15.9.6和Windows SDK 10.0.17134.0。
运行DMBridge可执行文件
若应用调用DM Bridge API时,DMBridge.exe
未运行,会抛出COMException
。需确保DMBridge.exe
已安装并作为服务运行,或使用DMBridge.exe -console
以管理员身份运行用于测试。更多使用方法见deploying DMBridge。
UWP应用使用示例
在UWP C#应用中使用DMBridgeComponenet
,示例代码如下:
```csharp
using DMBridgeComponent;
...
using (var serviceManager = new NTServiceBridge()) { int dhcpStatus = serviceManager.Query("dhcp"); } ``` 更完整的使用方法,包括异常处理,可参考the included sample或UWP API documentation。
非UWP应用使用示例
非UWP应用可直接调用DMBridge
提供的Rpc方法。以下是一个C程序示例:
```c
include "DMBridgeInterface_h.h"
include
include
define RPC_PROTOCOL_SEQUENCE L"ncalrpc"
define RPC_ENDPOINT L"DmBridgeRpcEndpoint"
int wmain(int argc, wchar_t argv[]) { / Create the Rpc handle */ RPC_WSTR stringBinding = nullptr; RPC_BINDING_HANDLE rpcHandle = nullptr;
RpcStringBindingCompose(
NULL,
(RPC_WSTR)RPC_PROTOCOL_SEQUENCE,
NULL,
(RPC_WSTR)RPC_ENDPOINT,
NULL,
&stringBinding);
RpcBindingFromStringBinding(stringBinding, &rpcHandle);
RpcStringFree(&stringBinding);
/* Call a DM Bridge API */
int dhcpStatus;
wchar_t* dhcpServiceName = const_cast<wchar_t*>(L"dhcp");
HRESULT ret = ::QueryServiceRpc(rpcHandle, dhcpServiceName, &dhcpStatus);
if (ret == S_OK)
{
// There were no errors
printf("DHCP service status: %d", dhcpStatus);
}
/* Close the Rpc handle */
RpcBindingFree(&rpcHandle);
return 0;
}
/ These must be included for Rpc / /********/ / MIDL allocate and free / /**********/ void __RPC_FAR * __RPC_USER midl_user_allocate(size_t len) { return(malloc(len)); }
void __RPC_USER midl_user_free(void __RPC_FAR * ptr) { free(ptr); } ``` 更完整的使用方法,包括异常处理,可参考DMBridgeComponent。
下载地址
点击下载 【提取码: 4003】【解压密码: www.makuang.net】