加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

delphi – CreateStdDispatch如何知道要调用的方法?

发布时间:2020-12-15 09:16:40 所属栏目:大数据 来源:网络整理
导读:我面临着实施 IDispatch 界面的问题.有四种方法,幸运的是其中有三种方法很简单: function TIEEventsSink.GetTypeInfoCount(...): HResult;{ Result := E_NOTIMPL;}function TIEEventsSink.GetTypeInfo(...): HResult;{ Result := E_NOTIMPL;}function TIEEv
我面临着实施 IDispatch界面的问题.有四种方法,幸运的是其中有三种方法很简单:

function TIEEventsSink.GetTypeInfoCount(...): HResult;
{
   Result := E_NOTIMPL;
}

function TIEEventsSink.GetTypeInfo(...): HResult;
{
   Result := E_NOTIMPL;
}

function TIEEventsSink.GetIDsOfNames(...): HResult;
{
   Result := E_NOTIMPL;
}

这是最后一种方法,Invoke很难.在这里,我面临着必须实际使用DispID,并调用我的适当方法;来自变量数组的unmarhsalling参数.

function Invoke(  
  dispIdMember: DISPID;
  riid: REFIID;
  lcid: LCID;
  wFlags: WORD;
  var pDispParams: DISPPARAMS;
  var pVarResult: VARIANT;
  var pExcepInfo: EXCEPINFO;
  var puArgErr: DWORD
): HRESULT;

不想编写所有繁琐的样板代码,我肯定会有错误,我去谷歌搜索 – 而不是做任何工作.

我在the MSDN Documentation of IDispatch.Invoke发现了这个snippit:

Generally,you should not implement Invoke directly.

优秀!我还是不想实现它!继续阅读:

Instead,use the dispatch interface to create functions 07002 and 07003. For details,refer to 07002,07003,07006 and 07007.

Creating the IDispatch Interface链接说:

You can implement IDispatch by any of the following means:

  • [snip]
  • Calling the 07002 function. This approach is the simplest,but it does not provide for rich error handling or multiple national languages.
  • [snip]

很好,CreateStdDispatch它是:

Creates a standard implementation of the IDispatch interface through a single function call. This simplifies exposing objects through Automation.

06002

我打算称它为:

CreateStdDispatch(
    myUnk,//Pointer to the object's IUnknown implementation.
    anotherObject,//Pointer to the object to expose.
    nil             //Pointer to the type information that describes the exposed object (i has no type info)
    dispInterface   //the IUnknown of the object that implements IDispatch for me
);

我无法弄清楚的是,CreateStdDispatch的Windows API实现如何知道在我的对象上调用哪些方法 – 特别是因为CreateStdDispatch不知道我正在使用什么面向对象的语言,或者它的调用约定.

CreateStdDispatch如何知道

>为给定的dispid调用什么方法?
>我语言的召集惯例?
>如何处理写入面向对象的语言的异常?

注意:我别无选择,只能实现调度接口;我没有定义the interface.我希望它是一个简单的早期绑定IUnknown,但它不是.

解决方法

传递给CreateStdDispatch的ITypeInfo参数是否公开了所有方法信息?

因此,您首先调用CreateDispTypeInfo创建类型信息并将其传递给CreateStdDispatch,然后CreateStdDispatch可以使用类型信息来确定要调用的方法,因为CreateDispTypeInfo需要包含所有这些信息的INTERFACEDATA

我可能会错,因为我没有时间研究它,但这对我来说是有道理的.我稍后会对此进行调查并更新答案.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读