现在的位置: 首页 > 综合 > 正文

InvokeHelper函数的用法

2013年12月15日 ⁄ 综合 ⁄ 共 2458字 ⁄ 字号 评论关闭

ActiveX控件的方法和属性操作与生成的C++类成员函数相关联都是通过InvokeHelper函数的调用来完成的,InvokeHelper函数的第一个参数是由Component Gallery(控件提供者)提供的。因为经过这样的处理,所以我们如果要调用ActiveX控件的方法或对其属性进行取和设置操作,只需调用生成的C++类对应的成员函数便可。

下面对InvokeHelper单独说明:
CWnd::InvokeHelper
void InvokeHelper( DISPID dwDispID, WORD wFlags, VARTYPE vtRet, void* pvRet, const BYTE* pbParamInfo, ... );
说明:
Call this member function to invoke the OLE control method or property specified by dwDispID, in the context specified by wFlags.
 
其中参数:
dwDispID:
//Identifies the method or property to be invoked. This value is usually supplied by Component Gallery.
 
wFlags:可以为下面些值,指明调用InvokeHelper的目的。
//[ DISPATCH_METHOD ]   The member is invoked as a method. If a property has the same name, both this and the DISPATCH_PROPERTYGET flag may be set.
[ DISPATCH_PROPERTYGET ] The member is retrieved as a property or data member.
[ DISPATCH_PROPERTYPUT ] The member is changed as a property or data member.
[ DISPATCH_PROPERTYPUTREF ] The member is changed by a reference assignment, rather than a value assignment. This flag is valid only when the property accepts a reference to an object.
 
vtRet:
//Specifies the type of the return value.
VT_EMPTY  void
VT_I2  short
VT_I4  long
VT_R4  float
VT_R8  double
VT_CY  CY
VT_DATE  DATE
VT_BSTR  BSTR
VT_DISPATCH  LPDISPATCH
VT_ERROR  SCODE
VT_BOOL  BOOL
VT_VARIANT VARIANT
VT_UNKNOWN  LPUNKNOWN
 
pvRet:
//Address of the variable that will that will receive the property value or return value. It must match the type specified by vtRet.
 
pbParamInfo:一般都设置为NULL
//Pointer to a null-terminated string of bytes specifying the types of the parameters following pbParamInfo.
specifies the types of the parameters passed to the method or property.
...:
//Variable List of parameters, of types specified in pbParamInfo.

 

 

CWnd::InvokeHelper

void InvokeHelper( DISPID dwDispID, WORD wFlags, VARTYPE vtRet, void* pvRet, const BYTE* pbParamInfo, ... );
  throw( COleException );
  throw( COleDispatchException );

参数:

dwDispID 标识了要激活的方法或属性。这个值通常是由组件廊提供的。
wFlags 描述了调用IDispatch::Invoke的上下文的标志。wFlags的可能取值参见《Win32 SDK OLE程序员参考》中的IDispatch::Invoke。
vtRet 指定了返回值的类型。可能的取值参见COleDispatchDriver::InvokeHelper的说明部分。
pvRet 将接收属性值或返回值的变量地址。它必须与vtRet指定的类型匹配。
pbParamInfo 指向一个以null结尾的字节字符串,指定了pbParamInfo后面的参数的类型。可能的取值参见COleDispatchDriver::InvokeHelper的说明部分。参数的变量列表,属于pbParamInfo所指定的类型。


说明:
调用这个函数以激活dwDispID所指定的OLE控件的方法或属性,使用wFlags指定的上下文。pbParamInfo参数指定了传递给方法或属性的参数的类型。在句法定义中参数的变量列表用...来代表。
这个函数将参数转换为VARIANTARG值,然后对OLE控件调用IDispatch::Invoke方法。如果对IDispatch::Invoke的调用失败,这个函数将抛出一个异常。如果IDispatch::Invoke返回的SCODE(状态码)是DISP_E_EXCEPTION,则这个函数抛出一个COleException对象;否则它抛出一个COleDispatchException对象。

注意 这个函数只能在代表OLE控件的CWnd对象内调用。


MSDN的解释:http://msdn.microsoft.com/zh-cn/library/vstudio/zwx803ex.aspx

抱歉!评论已关闭.