How To Assign the ActiveX Control LPDispatch Property in VB 4

Last reviewed: October 10, 1997
Article ID: Q153881
4.00 4.10 4.20 WINDOWS NT kbole kbprg

The information in this article applies to:

- The Microsoft Foundation Classes (MFC), included with:

  Microsoft Visual C++, 32-bit Edition, versions 4.0, 4.1, 4.2

SUMMARY

It is often useful for one ActiveX (OLE) Control to hold an LPDispatch pointer to another control on the same Visual Basic form. The first control can use this pointer to call methods and/or access properties on the second control using OLE Automation. This article demonstrates how to create a property of type LPDispatch on an MFC ActiveX Control, and how to properly set this property to another control's IDispatch pointer in Visual Basic.

NOTE: Although this article discusses properties of type LPDispatch, this information also applies to properties of type LPUnknown.

MORE INFORMATION

Follow these steps to add a property to a custom ActiveX control that is to hold another control's IDispatch pointer:

  1. Using ClassWizard, add a property of type LPDispatch to the control. Fill in a name for the property, and select the "Member Variable" button for this property.

  2. Next, you must initialize this member variable to NULL in the control's constructor. If you do not, Visual Basic will cause a General Protection Fault when you try to assign a value to it. This occurs because MFC tries to call Release() on the uninitialized pointer. If the pointer is set to NULL, Release() will not be called by MFC.

  3. Build the control, and place it on a form in Visual Basic.

The following lines of Visual Basic code demonstrate how to set the property to another control's IDispatch pointer:

   'Set the control's DispatchProp property to the DBCombo OLE control on
   'this form.
   Set MyOcx1.DispatchProp = DBCombo1

     . . .
     . . .

   'Don't forget to set this property to Nothing when finished
   Set MyOcx1.DispatchProp = Nothing

REFERENCES

For more information, please see the following article in the Microsoft Knowledge Base:

ARTICLE_ID: Q141414

TITLE     : How to Enumerate OLE and VB Controls from an OLE Control

Visual C++ Books Online, Programming with MFC Encyclopedia.


Additional reference words: 4.00 4.10 4.20 kbinf
KBCategory: kbole kbprg
KBSubcategory: MfcOle CDKIss
Keywords : CDKIss MfcOLE kbole kbprg
Technology : kbMfc
Version : 4.00 4.10 4.20
Platform : NT WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: October 10, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.