救命啊,就写了个简单的COM 接口类就出现N多个错误

tigertianx 2013-11-06 11:58:32
本人初学COM,对c++也不是很了解,只能说接触过,一直用C#开发的
就照着书写了接口类就出现N多个错误,求助大侠啊

#pragma once

class IMyUnknown
{
public:
virtual HRESULT _stdcall QueryInterface(const IID& iid, void * *ppv) = 0;
virtual ULONG _stdcall AddRef() = 0;
virtual ULONG _stdcall Release() =0;
};

错误信息:
e:\work project\test project\com\dictcomp\imyunknown.h(6) : error C2143: syntax error : missing ';' before '__stdcall'
e:\work project\test project\com\dictcomp\imyunknown.h(6) : error C2433: 'HRESULT' : 'virtual' not permitted on data declarations
e:\work project\test project\com\dictcomp\imyunknown.h(6) : error C2501: 'HRESULT' : missing storage-class or type specifiers
e:\work project\test project\com\dictcomp\imyunknown.h(6) : error C2143: syntax error : missing ',' before '&'
e:\work project\test project\com\dictcomp\imyunknown.h(6) : error C2059: syntax error : '&'
e:\work project\test project\com\dictcomp\imyunknown.h(6) : error C2253: 'QueryInterface' : pure specifier only applies to virtual function - specifier ignored
e:\work project\test project\com\dictcomp\imyunknown.h(7) : error C2143: syntax error : missing ';' before '__stdcall'
e:\work project\test project\com\dictcomp\imyunknown.h(7) : error C2433: 'ULONG' : 'virtual' not permitted on data declarations
e:\work project\test project\com\dictcomp\imyunknown.h(7) : error C2501: 'ULONG' : missing storage-class or type specifiers
e:\work project\test project\com\dictcomp\imyunknown.h(7) : error C2253: 'AddRef' : pure specifier only applies to virtual function - specifier ignored
e:\work project\test project\com\dictcomp\imyunknown.h(8) : error C2143: syntax error : missing ';' before '__stdcall'
e:\work project\test project\com\dictcomp\imyunknown.h(8) : error C2433: 'ULONG' : 'virtual' not permitted on data declarations
e:\work project\test project\com\dictcomp\imyunknown.h(8) : error C2501: 'ULONG' : missing storage-class or type specifiers
e:\work project\test project\com\dictcomp\imyunknown.h(8) : error C2253: 'Release' : pure specifier only applies to virtual function - specifier ignored

当然说白了这个3处错误都是同样的错误,但是本人愚钝就是找不出来
...全文
131 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
tigertianx 2013-11-07
  • 打赏
  • 举报
回复
谢谢啦,问题解决了,最后下了源代码,看了下 是因为没有定义接口类的标识符 typedef struct _GUID GUID; typedef GUID IID; extern "C" const IID IID_IUnknown = { 0x00000000, 0x0000, 0x0000, { 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46} } ; 引起的,不过话说回来,c++的报错有时候是和报错位置处的代码没有关系的, 而可能是因为代码不完整引起的,所以看错误信息让人摸不着头脑
tigertianx 2013-11-06
  • 打赏
  • 举报
回复
我建的是DLL工程啊,编译的时候就报了很多错
图灵狗 2013-11-06
  • 打赏
  • 举报
回复
参考http://www.vckbase.com/index.php/wv/1547.html
引用 楼主 tigertianx 的回复:
本人初学COM,对c++也不是很了解,只能说接触过,一直用C#开发的 就照着书写了接口类就出现N多个错误,求助大侠啊 #pragma once class IMyUnknown { public: virtual HRESULT _stdcall QueryInterface(const IID& iid, void * *ppv) = 0; virtual ULONG _stdcall AddRef() = 0; virtual ULONG _stdcall Release() =0; }; 错误信息: e:\work project\test project\com\dictcomp\imyunknown.h(6) : error C2143: syntax error : missing ';' before '__stdcall' e:\work project\test project\com\dictcomp\imyunknown.h(6) : error C2433: 'HRESULT' : 'virtual' not permitted on data declarations e:\work project\test project\com\dictcomp\imyunknown.h(6) : error C2501: 'HRESULT' : missing storage-class or type specifiers e:\work project\test project\com\dictcomp\imyunknown.h(6) : error C2143: syntax error : missing ',' before '&' e:\work project\test project\com\dictcomp\imyunknown.h(6) : error C2059: syntax error : '&' e:\work project\test project\com\dictcomp\imyunknown.h(6) : error C2253: 'QueryInterface' : pure specifier only applies to virtual function - specifier ignored e:\work project\test project\com\dictcomp\imyunknown.h(7) : error C2143: syntax error : missing ';' before '__stdcall' e:\work project\test project\com\dictcomp\imyunknown.h(7) : error C2433: 'ULONG' : 'virtual' not permitted on data declarations e:\work project\test project\com\dictcomp\imyunknown.h(7) : error C2501: 'ULONG' : missing storage-class or type specifiers e:\work project\test project\com\dictcomp\imyunknown.h(7) : error C2253: 'AddRef' : pure specifier only applies to virtual function - specifier ignored e:\work project\test project\com\dictcomp\imyunknown.h(8) : error C2143: syntax error : missing ';' before '__stdcall' e:\work project\test project\com\dictcomp\imyunknown.h(8) : error C2433: 'ULONG' : 'virtual' not permitted on data declarations e:\work project\test project\com\dictcomp\imyunknown.h(8) : error C2501: 'ULONG' : missing storage-class or type specifiers e:\work project\test project\com\dictcomp\imyunknown.h(8) : error C2253: 'Release' : pure specifier only applies to virtual function - specifier ignored 当然说白了这个3处错误都是同样的错误,但是本人愚钝就是找不出来
SKATE11 2013-11-06
  • 打赏
  • 举报
回复
是不是键工程建错了

64,680

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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