| title | ms.custom | ms.date | ms.prod | ms.reviewer | ms.suite | ms.technology | ms.tgt_pltfrm | ms.topic | f1_keywords | dev_langs | helpviewer_keywords | ms.assetid | caps.latest.revision | ms.author | manager | translation.priority.ht | |||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
COleDispatchDriver Class |
na |
10/14/2016 |
visual-studio-dev14 |
na |
na |
|
na |
reference |
|
|
|
3ed98daf-cdc7-4374-8a0c-cf695a8d3657 |
18 |
mblome |
ghogen |
|
Implements the client side of OLE automation.
class COleDispatchDriver
| Name | Description |
|---|---|
| COleDispatchDriver::COleDispatchDriver | Constructs a COleDispatchDriver object. |
| Name | Description |
|---|---|
| COleDispatchDriver::AttachDispatch | Attaches an IDispatch connection to the COleDispatchDriver object. |
| COleDispatchDriver::CreateDispatch | Creates an IDispatch connection and attaches it to the COleDispatchDriver object. |
| COleDispatchDriver::DetachDispatch | Detaches an IDispatch connection, without releasing it. |
| COleDispatchDriver::GetProperty | Gets an automation property. |
| COleDispatchDriver::InvokeHelper | Helper for calling automation methods. |
| COleDispatchDriver::ReleaseDispatch | Releases an IDispatch connection. |
| COleDispatchDriver::SetProperty | Sets an automation property. |
| Name | Description |
|---|---|
| COleDispatchDriver::operator = | Copies the source value into the COleDispatchDriver object. |
| COleDispatchDriver::operator LPDISPATCH | Accesses the underlying IDispatch pointer. |
| Name | Description |
|---|---|
| COleDispatchDriver::m_bAutoRelease | Specifies whether to release the IDispatch during ReleaseDispatch or object destruction. |
| COleDispatchDriver::m_lpDispatch | Indicates the pointer to the IDispatch interface attached to this COleDispatchDriver. |
COleDispatchDriver does not have a base class.
OLE dispatch interfaces provide access to an object's methods and properties. Member functions of COleDispatchDriver attach, detach, create, and release a dispatch connection of type IDispatch. Other member functions use variable argument lists to simplify calling IDispatch::Invoke.
This class can be used directly, but it is generally used only by classes created by the Add Class wizard. When you create new C++ classes by importing a type library, the new classes are derived from COleDispatchDriver.
For more information on using COleDispatchDriver, see the following articles:
COleDispatchDriver
Header: afxdisp.h
Call the AttachDispatch member function to attach an IDispatch pointer to the COleDispatchDriver object. For more information, see Implementing the IDispatch Interface.
void AttachDispatch(
LPDISPATCH lpDispatch,
BOOL bAutoRelease = TRUE
);
lpDispatch
Pointer to an OLE IDispatch object to be attached to the COleDispatchDriver object.
bAutoRelease
Specifies whether the dispatch is to be released when this object goes out of scope.
This function releases any IDispatch pointer that is already attached to the COleDispatchDriver object.
[!codeNVC_MFCOleContainer#3]
Constructs a COleDispatchDriver object.
COleDispatchDriver();
COleDispatchDriver( LPDISPATCH lpDispatch, BOOL bAutoRelease = TRUE );
COleDispatchDriver( const COleDispatchDriver& dispatchSrc );
lpDispatch
Pointer to an OLE IDispatch object to be attached to the COleDispatchDriver object.
bAutoRelease
Specifies whether the dispatch is to be released when this object goes out of scope.
dispatchSrc
Reference to an existing COleDispatchDriver object.
The form COleDispatchDriver( LPDISPATCH``lpDispatch, BOOLbAutoRelease = TRUE) connects the IDispatch interface.
The form COleDispatchDriver( constCOleDispatchDriver& dispatchSrc) copies an existing COleDispatchDriver object and increments the reference count.
The form COleDispatchDriver( ) creates a COleDispatchDriver object but does not connect the IDispatch interface. Before using COleDispatchDriver( ) without arguments, you should connect an IDispatch to it using either COleDispatchDriver::CreateDispatch or COleDispatchDriver::AttachDispatch. For more information, see Implementing the IDispatch Interface.
See the example for COleDispatchDriver::CreateDispatch.
Creates an IDispatch interface object and attaches it to the COleDispatchDriver object.
BOOL CreateDispatch(
REFCLSID clsid,
COleException* pError = NULL
);
BOOL CreateDispatch(
LPCTSTR lpszProgID,
COleException* pError = NULL
);
clsid
Class ID of the IDispatch connection object to be created.
pError
Pointer to an OLE exception object, which will hold the status code resulting from the creation.
lpszProgID
Pointer to the programmatic identifier, such as "Excel.Document.5", of the automation object for which the dispatch object is to be created.
Nonzero on success; otherwise 0.
[!codeNVC_MFCOleContainer#4]
Detaches the current IDispatch connection from this object.
LPDISPATCH DetachDispatch();
A pointer to the previously attached OLE IDispatch object.
The IDispatch is not released.
For more information about the LPDISPATCH type, see Implementing the IDispatch Interface in the [!INCLUDEwinSDK].
[!codeNVC_MFCOleContainer#5]
Gets the object property specified by dwDispID.
void GetProperty(
DISPID dwDispID,
VARTYPE vtProp,
void* pvProp ) const;
dwDispID
Identifies the property to be retrieved.
vtProp
Specifies the property to be retrieved. For possible values, see the Remarks section for COleDispatchDriver::InvokeHelper.
pvProp
Address of the variable that will receive the property value. It must match the type specified by vtProp.
[!codeNVC_MFCOleContainer#6]
Calls the object method or property specified by dwDispID, in the context specified by wFlags.
void AFX_CDECL InvokeHelper(
DISPID dwDispID,
WORD wFlags,
VARTYPE vtRet,
void* pvRet,
const BYTE* pbParamInfo, ... );
dwDispID
Identifies the method or property to be invoked.
wFlags
Flags describing the context of the call to IDispatch::Invoke. . For a list of possible values, see the wFlags parameter in IDispatch::Invoke in the [!INCLUDEwinSDK].
vtRet
Specifies the type of the return value. For possible values, see the Remarks section.
pvRet
Address of the variable that will receive the property value or return value. It must match the type specified by vtRet.
pbParamInfo
Pointer to a null-terminated string of bytes specifying the types of the parameters following pbParamInfo.
...
Variable list of parameters, of types specified in pbParamInfo.
The pbParamInfo parameter specifies the types of the parameters passed to the method or property. The variable list of arguments is represented by ... in the syntax declaration.
Possible values for the vtRet argument are taken from the VARENUM enumeration. Possible values are as follows:
| Symbol | Return Type |
|---|---|
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 |
The pbParamInfo argument is a space-separated list of VTS_ constants. One or more of these values, separated by spaces (not commas), specifies the function's parameter list. Possible values are listed with the EVENT_CUSTOM macro.
This function converts the parameters to VARIANTARG values, then invokes the IDispatch::Invoke method. If the call to Invoke fails, this function will throw an exception. If the SCODE (status code) returned by IDispatch::Invoke is DISP_E_EXCEPTION, this function throws a COleException object; otherwise it throws a COleDispatchException.
For more information, see VARIANTARG, Implementing the IDispatch Interface, IDispatch::Invoke, and Structure of COM Error Codes in the [!INCLUDEwinSDK].
See the example for COleDispatchDriver::CreateDispatch.
If TRUE, the COM object accessed by m_lpDispatch will be automatically released when ReleaseDispatch is called or when this COleDispatchDriver object is destroyed.
BOOL m_bAutoRelease;
By default, m_bAutoRelease is set to TRUE in the constructor.
For more information on releasing COM objects, see Implementing Reference Counting and IUnknown::Release in the [!INCLUDEwinSDK].
[!codeNVC_MFCOleContainer#9]
The pointer to the IDispatch interface attached to this COleDispatchDriver.
LPDISPATCH m_lpDispatch;
The m_lpDispatch data member is a public variable of type LPDISPATCH.
For more information, see IDispatch in the [!INCLUDEwinSDK].
See the example for COleDispatchDriver::AttachDispatch.
Copies the source value into the COleDispatchDriver object.
const COleDispatchDriver& operator=( const COleDispatchDriver& dispatchSrc );
dispatchSrc
A pointer to an existing COleDispatchDriver object.
Accesses the underlying IDispatch pointer of the COleDispatchDriver object.
operator LPDISPATCH();
[!codeNVC_MFCOleContainer#8]
Releases the IDispatch connection. For more information, see Implementing the IDispatch Interface
void ReleaseDispatch();
If auto release has been set for this connection, this function calls IDispatch::Release before releasing the interface.
See the example for COleDispatchDriver::AttachDispatch.
Sets the OLE object property specified by dwDispID.
void AFX_CDECL SetProperty(
DISPID dwDispID,
VARTYPE vtProp, ... );
dwDispID
Identifies the property to be set.
vtProp
Specifies the type of the property to be set. For possible values, see the Remarks section for COleDispatchDriver::InvokeHelper.
...
A single parameter of the type specified by vtProp.
[!codeNVC_MFCOleContainer#7]
MFC Sample CALCDRIV
MFC Sample ACDUAL
Hierarchy Chart
CCmdTarget Class