Sign in to follow this  
KEXIK

C++ pointers in two dlls

Recommended Posts

Hi! I have simple question to C++ win32 gurus. I have exe and few dlls, which are loaded dynamicaly using LoadLibrary(). When I allocate memory in one module or open a file using stdio FILE* fp=fopen() and then pass this pointer to second modude, I cannot delete this memory or write to this file. For example when I delete this memory allocated in other module I get: HEAP[test.exe]: Invalid Address specified to RtlValidateHeap( 00CD0000, 00DE2A88 ) Is it normal?

Share this post


Link to post
Share on other sites
Quote:
Original post by KEXIK
For example when I delete this memory allocated in other module I get: HEAP[test.exe]: Invalid Address specified to RtlValidateHeap( 00CD0000, 00DE2A88 )

Is it normal?

Yes. Each DLL has its own private allocation pool, its own private pool of file descriptors, etc. They cannot be allocated by one module and freed by another. File pointers are even worse, because they cannot be even used reliably in another DLL as the one they were created in.

So either make sure you always free the memory or use the FP in the same module they were created, or simply link to the DLL version of the MS CRT.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this