IDispatch invoke in C + + com Gets the object, note the point

Source: Internet
Author: User
Tags locale

Dispatch_propertyget

The member is retrieved as a property or data member.

This is the most critical address of this article, if the value you return is a COM object, will the caller increase AddRef? No, so you need to add the count yourself, or the program will soon crash



Provides access to properties and methods exposed by an object. The dispatch function Dispinvoke provides a standard implementation of Invoke.

Syntaxc++
HRESULT Invoke (  [in] dispid dispidmember,  [in] refiid riid,  [in] LCID lcid,  [in] WORD wflags,  [in, out] dispparams *pdispparams,  [out] VARIANT * Pvarresult,  [out] excepinfo *pexcepinfo,  [out] UINT *puargerr);
Parameters
Dispidmember [In]

Identifies the member. Use GetIDsOfNames or the object ' s documentation to obtain the dispatch identifier.

riid [In]

Reserved. Must be iid_null.

LCID [in]

The locale context in which to interpret arguments. The LCID is used by the getidsofnames function, and are also passed to Invoke to allow the OBJEC T to interpret it arguments specific to a locale.

Applications that does not support multiple national languages can ignore this parameter. For more information, refer to supporting multiple national Languages and exposing ActiveX Objects.

wflags [In]

Flags describing the context of the Invoke call.

Value meaning
Dispatch_method

The member is invoked as a method. If a property has the same name, both this and the DISPATCH_PROPERTYGET flag can is set.

Dispatch_propertyg ET

the member is retrieved as a property or data member.

This is the most critical address in this article, if the value you return is a COM object, will the caller increase AddRef? No, so you need to add the count yourself, or the program will crash soon

Dispatch_propertyp UT

the member is changed as a property or data member.


/p>

Dispatch_propertyputref

The member is changed by a reference assignment, rather than a value assignment. This flag was valid only if the property accepts a reference to an object.

pDispParams [In, out]

Pointer to a DISPPARAMS structure containing an array of arguments, an array of argument Dispids for named arguments, and Counts for the number of elements in the arrays.

Pvarresult [out]

Pointer to the location where the result was to be stored, or NULL if the caller expects no result. This argument are ignored if Dispatch_propertyput or DISPATCH_PROPERTYPUTREF is specified.

Pexcepinfo [out]

Pointer to a structure that contains exception information. This structure should are filled in if disp_e_exception is returned. Can be NULL.

Puargerr [out]

The index within rgvarg of the first argument that have an error. Arguments was stored in Pdispparams->rgvarg in reverse order, so the first argument was the one with the highest index I n the array. This parameter was returned only if the resulting return value is Disp_e_typemismatch or Disp_e_paramnotfound. This argument can is set to null. For details, see returning Errors.

Return value

This method can return one of these values.

Return Code Description
S_OK

Success.

Disp_e_badparamcount

The number of elements provided to Dispparams are different from the number of arguments accepted by the method or property .

Disp_e_badvartype

One of the arguments in Dispparams are not a valid variant type.

Disp_e_exception

The application needs to raise an exception. In this case, the structure passed in pexcepinfo should is filled in.

Disp_e_membernotfound

The requested member does not exist.

Disp_e_nonamedargs

This implementation of IDispatch does isn't support named arguments.

Disp_e_overflow

One of the arguments in Dispparams could is not being coerced to the specified type.

Disp_e_paramnotfound

One of the parameter IDs does not correspond to a parameter on the method. Puargerr is set to the first argument that contains the error.

Disp_e_typemismatch

One or more of the arguments could is coerced. The index of the first parameter with the incorrect type within Rgvarg are returned inpuargerr.

Disp_e_unknowninterface

The interface identifier passed in riid are not iid_null.

Disp_e_unknownlcid

The member being invoked interprets string arguments according to the LCID, and the LCID are not recognized. If The LCID is not needed to interpret arguments, this error should isn't be returned

Disp_e_paramnotoptional

A required parameter was omitted.

Remarks

Generally, you should not implement Invoke directly. Instead, use the dispatch interface to create functionscreatestddispatch and dispinvoke. For details, refer to createstddispatch, dispinvoke, Creating the IDispatch Interface and exposing Activ EX Objects.

If some Application-specific processing needs to be performed before calling a member, the code should perform the necessary actio NS, and then call itypeinfo::invoke to Invoke the member.  Itypeinfo::invoke   Acts exactly like  Invoke . The standard implementations of  Invoke  created by  Createstddispatch  and  dispinvoke defer to  Itypeinfo::invoke .

In an ActiveX client, Invoke should is used to get and set the values of properties, or to call a method of a Ac Tivex object. The dispidmember argument identifies the member to invoke. The Dispids that identify members is defined by the implementor of the object and can is determined by using the object ' s documentation, the IDispatch::GetIDsOfNames function, or the ITypeInfo interface.

When you use the IDispatch::Invoke () with dispatch_propertyput or dispatch_propertyputref, you have the to specially init Ialize the Cnamedargs and Rgdispidnamedargs elements of your DISPPARAMS structure with the following:

C++
DispID dispidnamed = Dispid_propertyput;dispparams.cnamedargs = 1;dispparams.rgdispidnamedargs = &dispidNamed;

The information that follows addresses developers of ActiveX clients and others, who use code to expose ActiveX objects. It describes the behavior that users of exposed objects should expect.

Requirements

Idl

Oaidl.idl
See Also
IDispatch

Community AdditionsADDArguments by Referenceif The method invoked returns a value via a VARIANT argument that was by ref or marked as [out] but I s not the default return value, then for the argument in question, if your pass in a simple VARIANT, you'll not get any V Alue back. The VARIANT passed in would remain unchanged. You had to pass a VARIANT by reference to the Invoke method. This can is set up as follows:

IDispatch invoke in C + + com Gets the object, note the point

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.