0

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

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

SYSTEM_POWER_STATUS_EX2是一个定义在 中的结构winbase.h,这个项目是一个 ATLSmartPhone 项目,winbase.h来自微软的 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.

那么如何导出使用 IDLSYSTEM_POWER_STATUS_EX2定义的结构呢?winbase.h

4

1 回答 1

0

您可以在单独的文件中编写IDL版本并仅将其导入:SYSTEM_POWER_STATUS_EX2IDLMIDL

cpp_quote("#if 0")
import "fake.idl";
cpp_quote("#else")
cpp_quote("#include <orginial_header>")
cpp_quote("#endif")
于 2012-05-27T09:15:00.300 回答