idl中定义的struct中的构造函数导致MIDL2025 [英] constructor in struct defined in idl leads to MIDL2025
问题描述
我一直遇到令人讨厌的编译器错误,告诉我我做的事情很不对劲.
我得到的错误是:错误MIDL2025:语法错误:期望"tagDevice"附近的类型规范.在IDL中定义了以下结构,该结构肯定与之相关,因为从常规.h/.cpp文件进行相同的编译(和工作)不会出现任何问题.
Hi, I keep running into a nasty compiler error telling me that I am doing something seriously wrong.
The error I get is: error MIDL2025 : syntax error : expecting a type specification near "tagDevice". The following struct is defined in the IDL which definitely has something to do with it as the same compiles (and works) without any problem from a regular .h / .cpp file.
typedef struct tagDevice
{
tagDevice()
{
DeviceName = NULL;
DeviceId = -1;
}
BSTR DeviceName;
int DeviceId;
}Device;
删除构造函数,然后全部编译就可以了,但是我不想每次都手动初始化值.
Remove the constructor and it all compiles OK but I don''t want to have to initialize the values manually each and every time.
Anybody got an idea of how I can get this to work?
推荐答案
总的来说,最好不要在结构上构造任何构造函数并对其进行处理,这是一个好主意.就像普通的旧数据一样.我确实相信COM希望使用不支持构造函数的C样式结构,以便可以解释您所看到的错误.
It''s generally a good idea not to have a constructor on a structure anyway and treat it like plain old data. I do believe COM expects C-style structs which do not support constructors, so that may explain the error you''re seeing.
这篇关于idl中定义的struct中的构造函数导致MIDL2025的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!