module (C++)

在 .idl 文件中定义了库块。

[ module ( 
   type=dll, 
   name=string, 
   version=1.0, 
   uuid=uuid, 
   lcid=integer, 
   control=boolean, 
   helpstring=string, 
   helpstringdll=string, 
   helpfile=string, 
   helpcontext=integer, 
   helpstringcontext=integer, 
   hidden=boolean, 
   restricted=boolean, 
   custom=string, 
   resource_name=string, 
) ];

参数

  • 类型 (可选)
    可以是如下内容之一:

    • dll 添加允许发生的 DLL 函数作为进程 COM 服务器的功能和类。 这是默认值。

    • exe 添加功能,并使所得到的可执行函数为的类处理 COM 服务器。

    • 服务添加允许所得到的可执行文件作为 NT 服务的功能和类。

    • 未指定 ATL 代码中禁用注入模块与属性相关:ATL 模块类的注入,全局实例 _AtlModule 和入口点函数。 不禁用 ATL 的代码注入由于在项目的其他属性。

  • 名称 (可选)
    库的名称块。

  • 版本 (可选)
    要分配给库块的版本号。 默认值为 1.0。

  • uuid
    库的唯一 ID。 如果省略此参数, ID 用于库将自动生成。 您可能需要检索库的 uuid 块,使用标识符 (__uuidoflibraryname**)**,可以执行。

  • LCID
    本地化参数。 请参见 LCID 有关更多信息。

  • 控件 (可选)
    指定所有 coclass 在库中为控件。

  • helpstring
    指定类型库。

  • helpstringdll (可选)
    设置 .dll 文件的名称使用执行文档查找字符串。 请参见 helpstringdll 有关更多信息。

  • helpfile (可选)
    帮助文件的名称类型库。

  • helpcontext (可选)
    此类型的库中用来帮助 ID。

  • helpstringcontext (可选)
    请参见 helpstringcontext 有关更多信息。

  • 隐藏 (可选)
    防止整个库中显示。 此用法旨在用于控件的使用。 宿主需要创建将使用扩展属性的控件的新类型库。 请参见 隐藏 MIDL 属性有关更多信息。

  • 限制 (可选)
    库的成员不能随机调用。 请参见 限制 MIDL 属性有关更多信息。

  • 自定义 (可选)
    一个或多个特性;这类似于 自定义 属性。 为 custom 的第一个参数是属性的 GUID。 例如:

    [module(custom={guid,1}, custom={guid1,2})]
    
  • resource_name
    .rgs 文件的字符串资源 ID 使用了注册 DLL,可执行文件或服务的 APP ID。 当模块是类型服务时,此参数也用于获取包含服务名的字符串的 ID。

备注

.rgs 文件和包含服务名的字符串应包含相同的数值。

备注

除非您指定 限制 参数传递给 emitidl模块 在使用 C++ 特性的所有过程需要。

库块将创建除了 模块 属性外,,如果为,则,源代码还使用 dispinterface对象或其中 coclass的特性。

一个库在 .idl 文件块允许。 在源代码的多个模块项将合并,在最近参数值实现。

如果此属性在使用 ATL 项目中使用,属性的行为更改。 除了上面的行为外,还属性插入全局对象 (称为 _AtlModule) 正确的类型和其他支持代码。 如果属性是独立的,该类从正确的模块类型派生的插入。 如果将特性应用于类,它添加正确的模块类型的基类。 正确的类型取决于 type 参数的值:

示例

下面的代码在生成的 .idl 文件演示如何创建库块。

// cpp_attr_ref_module1.cpp
// compile with: /LD
[module(name="MyLibrary", version="1.2", helpfile="MyHelpFile")];

以下代码表示,可以提供拥有由于使用 模块,将显示在代码注入函数的实现。 请参见 /Fx 有关查看插入的代码的更多信息。 为了重写 模块 属性插入的一个功能,使将包含该函数的实现的类并使 模块 特性应用于该类。

// cpp_attr_ref_module2.cpp
// compile with: /LD /link /OPT:NOREF
#include <atlbase.h>
#include <atlcom.h>
#include <atlwin.h>
#include <atltypes.h>
#include <atlctl.h>
#include <atlhost.h>
#include <atlplus.h>

// no semicolon after attribute block
[module(dll, name="MyLibrary", version="1.2", helpfile="MyHelpFile")] 
// module attribute now applies to this class
class CMyClass {
public:
BOOL WINAPI DllMain(DWORD dwReason, LPVOID lpReserved) {
   // add your own code here
   return __super::DllMain(dwReason, lpReserved);
   }
};

要求

属性上下文

适用对象

任何位置

可重复

必需的特性

无效的特性

有关更多信息,请参见 属性上下文

请参见

参考

usesgetlasterror

library

helpcontext

helpstring

helpfile

version (C++)

其他资源

IDL 特性

类特性

独立特性

Typedef、Enum、Union 和 Struct 特性

Attributes Samples