tags:

views:

95

answers:

2

If I have an app that uses at least two dlls, is it generally safe to allocate resources in one dll and free them in another?

I'm thinking specifically about calling fopen and fclose in different dlls, but I'd also like to know that it's safe for other resources (memory pointers, handles, etc...).

I think as long as everything is compiled with the same switches, it should work.

Thanks, Cory

A: 

As long as you're using the DLL version of the C runtime library (/MD or /MDd) then yes, it's safe.

If you're statically linking the CRT into either DLL (/MT or /MTd) then no, it's not safe.

RichieHindle
+3  A: 

This is a Bad Thing(TM) to do for all but non-trivial projects. This works under a very stringent set of conditions like version of the dlls, threading model, memory allocators used in each and a host of others. Finally, bugs will be too hard to chase.

dirkgently