生成存根文件

定义客户端/服务器接口后,通常会开发客户端和服务器源文件。 接下来,使用单个生成文件生成存根和头文件。 编译并链接客户端和服务器应用程序。 但是,如果这是你第一次接触分布式计算环境,你可能希望立即调用 MIDL 编译器,以查看 MIDL 生成的内容,然后再继续。 安装平台软件开发工具包 (SDK) 时,会自动安装 MIDL 编译器 (Midl.exe) 。

编译这些文件时,请确保 Hello.idl 和 Hello.acf 位于同一目录中。 以下命令将生成头文件 Hello.h 以及客户端和服务器存根,Hello_c.c 和 Hello_s.c。

midl hello.idl

请注意,Hello.h 包含 HelloProc 和 Shutdown 的函数原型,以及两个内存管理功能的正向声明, midl_user_allocatemidl_user_free。 将在服务器应用程序中提供这两个函数。 如果通过 [out] 参数将数据从服务器传输到客户端 () 则还需要在客户端应用程序中提供这两个内存管理功能。

请注意全局句柄变量的定义,hello_IfHandle,客户端和服务器接口句柄名称、hello_v1_0_c_ifspec和hello_v1_0_s_ifspec。 客户端和服务器应用程序将在运行时调用中使用接口句柄名称。

此时,无需对存根文件Hello_c.c 和 hello_s.c 执行任何操作。

/*file: hello.h */
/* this ALWAYS GENERATED file contains the definitions for the interfaces */
/* File created by MIDL compiler version 3.00.06 
/* at Tue Feb 20 11:33:32 1996 */
/* Compiler settings for hello.idl:
    Os, W1, Zp8, env=Win32, ms_ext, c_ext
    error checks: none */
//@@MIDL_FILE_HEADING(  )
#include "Rpc.h"
#include "rpcndr.h"
 
#ifndef __hello_h_
#define __hello_h_
 
#ifdef __cplusplus
extern "C"{
#endif 
 
/* Forward Declarations */ 
 
void __RPC_FAR * __RPC_USER MIDL_user_allocate(size_t);
void __RPC_USER MIDL_user_free( void __RPC_FAR * ); 
 
#ifndef __hello_INTERFACE_DEFINED__
#define __hello_INTERFACE_DEFINED__
 
/****************************************
 * Generated header for interface: hello
 * at Tue Feb 20 11:33:32 1996
 * using MIDL 3.00.06
 ****************************************/
/* [implicit_handle][version][uuid] */ 
 
            /* size is 0 */
void HelloProc( 
    /* [string][in] */ unsigned char __RPC_FAR *pszString);
    /* size is 0 */
void Shutdown( void);
extern handle_t hello_IfHandle;
 
extern RPC_IF_HANDLE hello_v1_0_c_ifspec;
extern RPC_IF_HANDLE hello_v1_0_s_ifspec;
#endif /* __hello_INTERFACE_DEFINED__ */
 
/* Additional Prototypes for ALL interfaces */
/* end of Additional Prototypes */
#ifdef __cplusplus
}
#endif
#endif