【问题标题】:How can I expose a method with a parameter of type IHTMLDocument* to COM from C++?如何从 C++ 向 COM 公开具有 IHTMLDocument* 类型参数的方法?
【发布时间】:2012-02-24 19:35:17
【问题描述】:

我有一个 C++ 库 (Win32),它填充了我想从 .NET(IE 工具栏)使用的网页中的一些字段,但我不知道如何通过 COM 公开该方法。我已经知道我应该将它添加到 .idl 文件中的接口中,如下所示:

interface IPlugin : IDispatch{
    #include <mshtml.h> 
    HRESULT FillFields(IHTMLDocument2* pDocument, BSTR value1, BSTR  value2);
};

但是 mshtml.h 的#include 给了我以下错误:

error MIDL2003: redefinition : _LARGE_INTEGER
error MIDL2003: redefinition : _ULARGE_INTEGER
error MIDL2003: redefinition : INT
error MIDL2003: redefinition : Int64ShllMod32

有什么方法可以将 IHTMLDocument 对象从 C# 传递到 C++ 并在 C++ 中修改它的内容,或者 COM 是否应该仅用于自动化的类型,如 BSTR?

谢谢

【问题讨论】:

  • 尝试将#include 移出interface
  • @spencercw 我想我只能在界面之外导入其他 .idls,因为如果我尝试包含 .h 会出现此错误:error MIDL2025: syntax error : expecting an interface name or DispatchInterfaceName or CoclassName or ModuleName or LibraryName or ContractName or a type specification near "pragmawarning( disable: 4049 ) File: mshtmlc.h

标签: c# c++ com com-interop


【解决方案1】:

您可以使用#importIHTMLDocument2 的IDL 定义纳入MIDL 的范围内。

MIDL 编译器将为您生成#include。 MIDL 文件中的显式#include 仅在极少数情况下有用。

【讨论】:

  • import "mshtml.idl"; after import "ocidl.idl"; 确实是解决方案,谢谢
猜你喜欢
  • 2016-01-04
  • 2010-12-31
  • 2014-01-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-01
相关资源
最近更新 更多