Original Post
I’m writing a program that uses both an exe and dll using Microsoft Visual C++ 7. I need the dll to hold the mouse and keyboard hook procs for idle monitoring for older OS’s that don’t support the GetLastInputInfo function, as well as to store the COM interfaces to use context menus for files and folders in explorer. The program uses a large tree structure that is shared by the dll and the exe, and the memory for this tree is allocated dynamically with the new and delete operators in both the dll and exe. Because the memory is allocated in mixed places, some in the dll’s memory heap and some in the exe’s memory heap, I get an "...Invalid Address specified to RtlValidateHeap..." error when I try to free all the memory within the exe, because the delete operator can not free the memory allocated in the dll’s memory heap, even through the exe can read and write the memory for the dll and visa versa. The way around this is to make sure that they share the same heap. The only way I know of is to set the runtime library for both the dll and exe to "Multi-theaded DLL". This works fine, except the dll and exe both link to msvcr70.dll instead of the libraries being included within the exe and dll files. I’d prefer not to have to distribute this dll with my program because not all computers have this file, especially operating systems older than Windows XP. Other than overriding the new and delete operators to use VirtualAlloc to allocate the memory, (I use VirtualAlloc to share memory with system dll’s in my program, so I’d assume this would work), what can I do?