devxlogo

NT Sharing C++ Objects Through Memory Mapped Files

NT Sharing C++ Objects Through Memory Mapped Files

Question:
I am writing a Microsoft ISAPI-based application using MFC classes. We need to get access to some of the objects used within the application from an NT service.

I tried using Memory mapped files, backed by the System Paging file to achieve this ?all looks ok, and we can retrieve a pointer to the object from the second process?however, any ASSERT_VALID() call fails with a report of an invalid vtable. I can understand why this is happening, but is there any way to ‘repair’ the class from the second process, and create a valid vtable?

Answer:
Unfortunately, the value of the vfptr (which is a pointer to a compiler-generated table that contains the memory addresses of a class’s virtual member functions) is valid only within the address space of its process.

You cannot access it from another process safely. If you wish to call a virtual function from another process, there’s no escape from using non-standard features such as COM, CORBA or any other forms of distributed objects.

See also  Monetize TikTok For Your Business
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist