使用VC多年了,今天发现VC一个完全没接触过的语法,汗颜...!谁能帮忙解释一下

永夜星空 2011-12-22 08:23:52
今天在MSDN上搜索关键字"__uuidof"的功能(这个东西也不懂,但这不是重点)
MSDN列出了一个例子:


// expre_uuidof.cpp
// compile with: ole32.lib
#include "stdio.h"
#include "windows.h"

[emitidl];
[module(name="MyLib")];
[export]
struct stuff {
int i;
};

int main() {
LPOLESTR lpolestr;
StringFromCLSID(__uuidof(MyLib), &lpolestr);
wprintf_s(L"%s", lpolestr);
CoTaskMemFree(lpolestr);
}



其中这几行:
[emitidl];
[module(name="MyLib")];
[export]
开始还以为这是注解什么的,但是我原封不动复制到VC里竟然能运行.
真是不知道是什么语法,甚至不知道着是语法还是宏还是别的什么.还有它的作用是什么呢?
谁能给我解释一下么.先谢谢了.

我擅自增加了一行:
[kkksss]
结果编译器提示:
error C2337: “kkkss”: 未找到属性

这个我都不知道去哪里找资料,因为不知道在网上搜索什么关键字
...全文
202 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
_free 2011-12-23
  • 打赏
  • 举报
回复
msdn搜索
[Quote=引用 5 楼 liuhua1982 的回复:]
引用 2 楼 zz_lgy 的回复:
首次见,扩展阅读了下

Determines whether all subsequent IDL attributes will be processed and placed in the generated .idl file.


[ emitidl([boolean],
defaultimports=[boolean]
) ] ;
……
[/Quote]
lgstudyvc 2011-12-22
  • 打赏
  • 举报
回复
学习2下,楼下说
永夜星空 2011-12-22
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 zz_lgy 的回复:]
首次见,扩展阅读了下

Determines whether all subsequent IDL attributes will be processed and placed in the generated .idl file.


[ emitidl([boolean],
defaultimports=[boolean]
) ] ;


Defines the l……
[/Quote]
你这些是在哪里找到的呢?
战在春秋 2011-12-22
  • 打赏
  • 举报
回复
这是atl 7.0 以后添加的,称为属性编程。
英文关键字为Attributed Programming,如有兴趣,可搜索msdn。

属性编程看起来编码似乎更简单,但是受限太多,缺少足够的灵活性,而且出错难以找到原因,实际上应用并不多。楼主大致了解一下即可,不用花费太多时间。
leetow2003 2011-12-22
  • 打赏
  • 举报
回复
这个好像用在COM中比较多
_free 2011-12-22
  • 打赏
  • 举报
回复
首次见,扩展阅读了下

Determines whether all subsequent IDL attributes will be processed and placed in the generated .idl file.


[ emitidl([boolean],
defaultimports=[boolean]
) ] ;


Defines the library block in the .idl file.


[ 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,
) ];

jyh_baoding 2011-12-22
  • 打赏
  • 举报
回复
是关键字吧,不过没接触过
redui 2011-12-22
  • 打赏
  • 举报
回复
限制太多,VC2008已经不再推荐属性编程了,还是老老实实地放到IDL里去。
请叫我涛哥0-0 2011-12-22
  • 打赏
  • 举报
回复
COM中的属性,看看这吧:
After the emitidl C++ attribute is encountered in a source code file, IDL category attributes will be placed in the generated .idl file. If there is no emitidl attribute, IDL attributes in the source code file will be output to the generated .idl file.

It is possible to have multiple emitidl attributes in a source code file. If [emitidl(false)]; is encountered in a file without a subsequent [emitidl(true)];, then no attributes will be processed into the generated .idl file.

Each time the compiler encounters a new file, emitidl is implicitly set to true.

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧