Click here to Skip to main content
16,010,427 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Help with CMutex and DB access Pin
Joaquín M López Muñoz6-Nov-01 9:03
Joaquín M López Muñoz6-Nov-01 9:03 
GeneralRe: Help with CMutex and DB access Pin
Bill Wilson6-Nov-01 10:21
Bill Wilson6-Nov-01 10:21 
GeneralSetting a CEditView to read-only Pin
Simon Walton5-Nov-01 12:48
Simon Walton5-Nov-01 12:48 
GeneralRe: Setting a CEditView to read-only Pin
PJ Arends5-Nov-01 14:16
professionalPJ Arends5-Nov-01 14:16 
GeneralDLL/App Memory Allocation Pin
Steve The Plant5-Nov-01 11:09
Steve The Plant5-Nov-01 11:09 
GeneralRe: DLL/App Memory Allocation Pin
Joaquín M López Muñoz5-Nov-01 11:19
Joaquín M López Muñoz5-Nov-01 11:19 
GeneralRe: DLL/App Memory Allocation Pin
Steve The Plant5-Nov-01 11:41
Steve The Plant5-Nov-01 11:41 
GeneralRe: DLL/App Memory Allocation Pin
Joaquín M López Muñoz5-Nov-01 12:08
Joaquín M López Muñoz5-Nov-01 12:08 
Well, actually it's magic Poke tongue | ;-P
Now seriously, what's happening here is this:
Both your client app and your DLL are having access to cClass.h and cClass.cpp, and both modules are subsequently compiling and linking their own copies of cClass::AllocMem(). Now, when you pass a pointer to a cClass object created by the app to the DLL, and the DLL code executes pcClass->AllocMem(), what it is actually doing is invoking its own version of cClass::AllocMem() against pcClass: crash promptly ensues when the clients tries to free the memory allocated, for the reasons you already diagnosed.
Now, if you make cClass::AllocMem() virtual, then the DLL does not execute any local version of the method, but instead uses pcClass to locate its associated virtual table and AllocMem() implementation, both of which reside at the app's home (which originally created the object). Having things arranged like this, you can even remove cClass.cpp from the DLL build and things will still work as long as the DLL limits itself to handle cClass pointers passed from the app, and all relevant methods are virtualized. This is also a good thing to have in the light of OO, as it defines an interface contract between the app and the DLL and allows you to change the implementation code without the DLL knowing nor having to be recompiled.

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
GeneralRe: DLL/App Memory Allocation Pin
Steen Krogsgaard6-Nov-01 4:16
Steen Krogsgaard6-Nov-01 4:16 
GeneralRe: DLL/App Memory Allocation Pin
Joaquín M López Muñoz6-Nov-01 6:43
Joaquín M López Muñoz6-Nov-01 6:43 
GeneralRe: DLL/App Memory Allocation Pin
Steen Krogsgaard6-Nov-01 22:01
Steen Krogsgaard6-Nov-01 22:01 
GeneralPut value in the registry Pin
Peter Liddle5-Nov-01 10:32
Peter Liddle5-Nov-01 10:32 
GeneralRe: Put value in the registry Pin
Christian Graus5-Nov-01 10:36
protectorChristian Graus5-Nov-01 10:36 
GeneralRe: Put value in the registry Pin
Carlos Antollini5-Nov-01 10:58
Carlos Antollini5-Nov-01 10:58 
GeneralRe: Put value in the registry Pin
5-Nov-01 15:14
suss5-Nov-01 15:14 
GeneralDynamic Multidimensional Array or Alternatives Pin
Steve L.5-Nov-01 9:43
Steve L.5-Nov-01 9:43 
GeneralRe: Dynamic Multidimensional Array or Alternatives Pin
Ravi Bhavnani5-Nov-01 10:05
professionalRavi Bhavnani5-Nov-01 10:05 
GeneralRe: Dynamic Multidimensional Array or Alternatives Pin
Chris Losinger5-Nov-01 10:09
professionalChris Losinger5-Nov-01 10:09 
GeneralRe: Dynamic Multidimensional Array or Alternatives Pin
Remi Morin5-Nov-01 10:15
Remi Morin5-Nov-01 10:15 
GeneralRe: Dynamic Multidimensional Array or Alternatives Pin
Todd Smith5-Nov-01 13:29
Todd Smith5-Nov-01 13:29 
GeneralRe: Dynamic Multidimensional Array or Alternatives Pin
Sprudling6-Nov-01 3:49
Sprudling6-Nov-01 3:49 
GeneralRe: Dynamic Multidimensional Array or Alternatives Pin
Remi Morin7-Dec-01 6:36
Remi Morin7-Dec-01 6:36 
GeneralRe: Dynamic Multidimensional Array or Alternatives Pin
Sprudling7-Dec-01 6:41
Sprudling7-Dec-01 6:41 
GeneralRe: Dynamic Multidimensional Array or Alternatives Pin
Malcolm McMahon6-Nov-01 4:08
Malcolm McMahon6-Nov-01 4:08 
GeneralStatic control question.... Pin
Rickard Andersson205-Nov-01 8:29
Rickard Andersson205-Nov-01 8:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.