使用ATL的IDL导出winbase.h中定义的struct

时间:2012-01-08 08:44:35

标签: windows-ce atl idl windows-mobile-6.5

这是我在IDL中定义的方法:

[id(3), helpstring("method GetBatteryStatus")] 
HRESULT GetBatteryStatus([out,retval] SYSTEM_POWER_STATUS_EX2* batteryStatus);

SYSTEM_POWER_STATUS_EX2winbase.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结构?

1 个答案:

答案 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")
相关问题