Microsoft KB Archive/247273

= BUG: IOleObjectImpl<>::DoVerb Does Not Process Positive Verbs Correctly =

Article ID: 247273

Article Last Modified on 10/2/2003

-

APPLIES TO


 * Microsoft ActiveX Template Library 2.0
 * Microsoft ActiveX Template Library 2.1
 * Microsoft ActiveX Template Library 3.0

-



This article was previously published under Q247273



SYMPTOMS
According to documentation for IOleObject::DoVerb, unknown positive verbs should be treated as the primary verb and OLEOBJ_S_INVALIDVERB should be returned. ATL's implementation of IOleObject::DoVerb does nothing for positive verbs and returns E_NOTIMPL.



CAUSE
This is a bug in the ATL implementation of IOleObject::DoVerb.



RESOLUTION
To correct this behavior, you can override the ATL function IOleObjectImpl::DoVerb. You need to override the IOleObjectImpl::DoVerb function for every ATL object that needs to have the correct processing for IOleObject::DoVerb. Because this may need to be done for more than one ATL COM object in your project, it is recommended that you create a new template class derived from IOleObjectImpl. You can use the following steps to accomplish this:  Create a new header file and insert it into your ATL project. Give the header file the name MyIOleObjectImpl.h.  Open MyIOleObjectImpl.h created in step 1 and copy the following code into the file:
 * 1) ifndef MYIOLEOBJECTIMPL_H
 * 2) define MYIOLEOBJECTIMPL_H


 * 1) include 

template  class IMyOleObjectImpl : public IOleObjectImpl { public: STDMETHODIMP DoVerb(LONG iVerb, LPMSG pMsg, IOleClientSite* pActiveSite, LONG lindex, HWND hwndParent, LPCRECT lprcPosRect ) {    if (iVerb > 0) {       iVerb = OLEIVERB_PRIMARY; IOleObjectImpl::DoVerb(iVerb, pMsg, pActiveSite, lindex, hwndParent, lprcPosRect); return OLEOBJ_S_INVALIDVERB; }

return IOleObjectImpl::DoVerb(iVerb, pMsg, pActiveSite, lindex, hwndParent, lprcPosRect); } };

 Save and close MyIOleObjectImpl.h.  Open your ATL COM object header file and add the following code before the class declaration: </li>  Inside of your ATL COM object class derivation, change the existing derivation from IOleObjectImpl to IMyOleObjectImpl. The code should appear similar to the following: class ATL_NO_VTABLE CATLCONTROLObj1 : // Rest of classes omitted for brevity. // public IOleObjectImpl<CATLCONTROLObj1>, public IMyOleObjectImpl<CATLCONTROLObj1>, public CComCoClass<CATLCONTROLObj1, &CLSID_ATLCONTROLObj1> { // Rest of code omitted for brevity. };                       </li> Save your ATL COM object header file and rebuild the project.</li></ol>
 * 1) endif
 * 1) include "MyIOleObjectImpl.h"

After performing these steps, you should notice that IOleObject::DoVerb is implemented correctly when a positive verb is passed.

<div class="status_section">

STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

<div class="references_section">