【问题标题】:Export struct defined in winbase.h with ATL's IDL使用 ATL 的 IDL 导出在 winbase.h 中定义的结构
【发布时间】:2012-02-05 06:37:19
【问题描述】:

这是我在 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"

如果我在 IDL 文件的顶部添加import "winbase.h",错误将是:

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.

那么如何使用 IDL 导出 winbase.h 中定义的 SYSTEM_POWER_STATUS_EX2 结构?

【问题讨论】:

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


    【解决方案1】:

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

    cpp_quote("#if 0")
    import "fake.idl";
    cpp_quote("#else")
    cpp_quote("#include <orginial_header>")
    cpp_quote("#endif")
    

    【讨论】:

      猜你喜欢
      • 2018-11-20
      • 2021-05-30
      • 2012-08-14
      • 1970-01-01
      • 1970-01-01
      • 2011-02-09
      • 2010-09-27
      • 2014-08-05
      • 2015-07-02
      相关资源
      最近更新 更多