这是我在IDL中定义的方法:
[id(3), helpstring("method GetBatteryStatus")]
HRESULT GetBatteryStatus([out,retval] SYSTEM_POWER_STATUS_EX2* batteryStatus);
SYSTEM_POWER_STATUS_EX2
是winbase.h
中定义的结构,此项目是ATLSmartPhone项目,winbase.h
来自Microsoft的SDK。
编译项目时,错误是:
error MIDL2025 : syntax error : expecting a type specification near "SYSTEM_POWER_STATUS_EX2"
如果我将import "winbase.h"
添加到IDL文件的顶部,则错误将为:
error MIDL2003 : redefinition : size_t; error MIDL2003 : redefinition : _LARGE_INTEGER;.....
然后,如果我在IDL中添加typedef:
typedef[public,uuid(37DE998A-6787-415a-A191-861C315D1248),helpstring("Power Status")]
struct _SYSTEM_POWER_STATUS_EX2 {
...
...
} SYSTEM_POWER_STATUS_EX2;
错误将是:
error C2011: '_SYSTEM_POWER_STATUS_EX2' : 'struct' type redefinition.
那么如何导出SYSTEM_POWER_STATUS_EX2
中使用IDL定义的winbase.h
结构?
答案 0 :(得分:0)
您可以在单独的IDL
文件中写下SYSTEM_POWER_STATUS_EX2
IDL
版本,并仅将其导入MIDL
:
cpp_quote("#if 0")
import "fake.idl";
cpp_quote("#else")
cpp_quote("#include <orginial_header>")
cpp_quote("#endif")