MFC Objects Cannot be Passed to Another Process

Last reviewed: July 22, 1997
Article ID: Q115141
1.00 1.50 1.51 1.52 WINDOWS kbprg

The information in this article applies to:

  • The Microsoft Foundation Classes (MFC) included with: Microsoft Visual C++ for Windows, versions 1.0, 1.5, 1.51, and 1.52

SUMMARY

The memory used by MFC objects comes either from the application's stack (in the case of automatic variables), or from the application's heap (in the case of dynamic allocations). In either case, the memory belongs to the application that created the MFC object. The memory is not allocated with GMEM_DDESHARE. As a result, objects instantiated from MFC classes cannot be passed from one application to another.

Each MFC class built with debug information contains several ASSERT statements in its member functions that ensure object integrity. One such statement, ASSERT_VALID( this ), calls AfxIsValidAddress(). AfxIsValidAddress() verifies that the memory for the MFC object lies within a read/write segment. When an application attempts to use an MFC object which it did not create, the memory is not readable or writeable, so the call fails with an assertion.

MORE INFORMATION

For example, define an OLE Automation method that returns a pointer to an MFC object. It appears that the pointer is correctly passed, but any attempt to call a member function of the class of that object results in an assertion.

One solution to the problem of passing MFC objects is to make a copy of that object's data in shareable memory and pass a handle for that memory to the receiving application. The receiving application must have the same class defined in order to instantiate an object and initialize it with the data received from the sending application. In the OLE example in the previous paragraph, the OLE Automation server could pass the member variables for an object in a BSTR or SAFEARRAY.


Additional reference words: kbinf 1.00 1.50 1.51 1.52 2.00 2.50 2.51 2.52
KBCategory: kbprg
KBSubcategory: MfcMisc
Keywords : kb16bitonly
Technology : kbMfc


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: July 22, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.