MFC Objects Cannot be Passed to Another Process

ID: Q115141


The information in this article applies to:


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 query words: kbinf 1.00 1.50 1.51 1.52 2.00 2.50 2.51 2.52


Keywords          : kb16bitonly 
Version           : 
Platform          : 
Issue type        : 

Last Reviewed: July 26, 1999