生成 UUID 和模版(IDL)文件
定义接口的第一步是使用 uuidgen 实用工具生成通用唯一标识符(UUID)。UUID使客户端和服务端能够相互识别。该工具包含在阿庄平台软件开发工具包中(SDK)。
一般安装路径位于:D:\Windows Kits\10\bin\10.0.22621.0\x64
以下命令生成 UUID 并创建名为 Hello.idl 的模版文件。
uuidgen /i /ohello.idl
模版内容大致如下:
[
uuid(7a98c250-6808-11cf-b73b-00aa00b677a7),
version(1.0)
]
interface hello
{
}
添加接口
//file hello.idl
[
uuid(7a98c250-6808-11cf-b73b-00aa00b677a7),
version(1.0)
]
interface hello
{
void HelloProc([in, string] unsigned char * pszString);
void Shutdown(void);
}
添加 acf 文件
acf文件内容如下所示,导出接口需要与 idl 文件一致:
//file: hello.acf
[
implicit_handle (handle_t hello_IfHandle)
]
interface hello
{
}
编译 idl 文件
打开 visual studio,新建一个空项目
空项目中添加上述 idl文件 和 acf文件
编译项目
生成 hello_h.h、hello_c.c、hello_s.c
hello_h.h: 服务端和客户端共用文件
hello_c.c: 客户端文件
hello_s.c: 服务端文件
需要补充说明的是,在 hello_h.h 头文件中有两个导出接口,导出接口即为rpc调用的接口。
extern RPC_IF_HANDLE he