接口定义语言MIDL:Microsoft Interface Definition Language。
MIDL是定义COM接口的说明性语言。是一种独立于语言的接口定义方式,从而产生RPC(Remote Procedure Call,远程调用过程)处理和实现接口定义的COM的服务。
COM服务器的三个关键要求:
1、接口(Interface)
客户端访问服务器的入口,即通过接口调用服务器函数
2、组件类(CoClass)
接口的具体实现
3、类型库(Type library)
编译的IDL文件,向支持COM的环境传送接口的信息
IDL文件实例
import "oaidl.idl";
[
object,
uuid(57140480-CB78-11d2-91A6-0008C7FE9130)
]
interface IFirstInterface : IUnknown
{
HRESULT DoSomething();
};
[
uuid(57140482-CB78-11d2-91A6-0008C7FE9130),
version(1.0)
]
library FirstTypeLib
{
importlib("stdole32.tlb");
[
uuid(57140483-CB78-11d2-91A6-0008C7FE9130)
]
coclass FirstComponent
{
[default] interface IFirstInterface;
};
};
[]表示是一组属性
第一个属性是object,告诉IDL编译器这是COM接口定义的。
uuid定义的GUID是接口的唯一标识(ID)。
属性后面是接口定义本身。
coclass FirstComponent是定义组件类。
MIDL编译器的参数选项
Microsoft (R) 32b/64b MIDL Compiler Version 7.00.0555
Copyright (c) Microsoft Corporation. All rights reserved.
-MIDL COMPILER OPTIONS-
-MODE-
/ms_ext Microsoft extensions to the IDL language (default)
/c_ext Allow Microsoft C extensions in the IDL file (default)
/osf OSF mode - disables /ms_ext and /c_ext options
/app_config Allow selected ACF attributes in the IDL file
/mktyplib203 MKTYPLIB Version 2.03 compatiblity mode
-INPUT-
/acf filename Specify the attribute configuration file
/I directory-list Specify one or more directories for include path
/no_def_idir Ignore the current and the INCLUDE directories
-OUTPUT FILE GENERATION-
/client none Do not generate client files
/client stub Generate client stub file only
/out directory Specify destination directory for output files
/server none Generate no server files
/server stub Generate server stub file only
/syntax_check Check syntax only; do not generate output files
/Zs Check syntax only; do not generate output files
/oldtlb Generate old format type libraries
/newtlb Generate new format type libraries (default)
[ Press <return> to continue ]
/notlb Don't generate the tlb file
-OUTPUT FILE NAMES-
/cstub filename Specify client stub file name
/dlldata filename Specify dlldata file name
/h filename Specify header file name
/header filename Specify header file name
/iid filename Specify interface UUID file name
/proxy filename Specify proxy file name
/sstub filename Specify server stub file name
/tlb filename Specify type library file name
-C COMPILER AND PREPROCESSOR OPTIONS-
/cpp_cmd cmd_line Specify name of C preprocessor (default: cl.exe)
/cpp_opt options Specify additional C preprocessor options
/D name[=def] Pass #define name, optional value to C preprocessor
/no_cpp Turn off the C preprocessing option
/nocpp Turn off the C preprocessing option
/U name Remove any previous definition (undefine)
/msc_ver <nnnn> Microsoft C/C++ compiler version
/savePP Save the preprocessed temporary file(s)
-ENVIRONMENT-
[ Press <return> to continue ]
/char signed C compiler default char type is signed
/char unsigned C compiler default char type is unsigned
/char ascii7 Char values limited to 0-127
/env win32 Target environment is Microsoft Windows 32-bit (NT)
/env ia64 Target environment is Microsoft Windows 64-bit (NT) for IA64
/env x64 Target environment is Microsoft Windows for 64-Bit
Extended Systems
/lcid Locale id for international locales
/ms_union Use Midl 1.0 non-DCE wire layout for non-encapsulated unions
/oldnames Do not mangle version number into names
/rpcss Automatically activate rpc_sm_enable_allocate
/use_epv Generate server side application calls via entry-pt vector
/no_default_epv Do not generate a default entry-point vector
/prefix client str Add "str" prefix to client-side entry points
/prefix server str Add "str" prefix to server-side manager routines
/prefix switch str Add "str" prefix to switch routine prototypes
/prefix all str Add "str" prefix to all routines
/win32 Target environment is Microsoft Windows 32-bit (NT)
/ia64 Target environment is Microsoft Windows 64-bit (NT) for IA64
/x64 Target environment is Microsoft Windows for 64-Bit
Extended Systems
/protocol dce Use DCE NDR transfer syntax (default for 32b)
/protocol all Use all supported transfer syntaxes
[ Press <return> to continue ]
/protocol ndr64 Use Microsoft extension NDR64 transfer syntax
/target {system} Set the minimum target system
-RUNTIME ERROR CHECKING BY STUBS-
/error all Turn on all the error checking options, the best flavor
/error none Turn off all the error checking options
/error allocation Check for out of memory errors
/error bounds_check Check size vs transmission length specification
/error enum Check enum values to be in allowable range
/error ref Check ref pointers to be non-null
/error stub_data Emit additional check for server side stub data validity
All the /error checking above are replaced by /robust
/robust Generate additonal information to validate parameters.
Requires Windows 2000 and after (default)
/no_robust turn off /robust feature. not applicable for 64-bit Windows
-OPTIMIZATION-
/align {N} Designate packing level of structures
/pack {N} Designate packing level of structures
/Zp {N} Designate packing level of structures
/no_format_opt Skip format string reusage optimization
/Oi Generate fully interpreted stubs, old style
-Oicf is usually better
[ Press <return> to continue ]
/Oic Generate fully interpreted stubs for standard interfaces and
stubless proxies for object interfaces as of NT 3.51 release
using -Oicf instead is usually better
/Oicf Generate fully interpreted stubs with extensions and stubless
proxies for object interfaces as of NT 4.0 release (default)
/Oif Same as -Oicf
/Os Generate inline stubs
-MISCELLANEOUS-
@response_file Accept input from a response file
/? Display a list of MIDL compiler switches
/confirm Display options without compiling MIDL source
/help Display a list of MIDL compiler switches
/nologo Supress displaying of the banner lines
/o filename Redirects output from screen to a file
/W{0|1|2|3|4} Specify warning level 0-4 (default = 1)
/WX Report warnings at specified /W level as errors
/no_warn Suppress compiler warning messages
来源:CSDN
作者:道格拉斯范朋克
链接:https://blog.csdn.net/xinqingwuji/article/details/51919953