1

Does anyone know a good library/solution for smart references across dll boundaries?

This is the intended use case:

  1. Main program loads dll
  2. dll allocates memory and returns a smart_ref
  3. main program uses smart ref (always checks if it is valid)
  4. dll gets unloaded (lose coupling)
  5. main should not crash on checking smart_ref
Sergey K.
  • 24,894
  • 13
  • 106
  • 174
user1362700
  • 155
  • 8
  • See this Q/A on the same topic: http://stackoverflow.com/questions/1344126/memory-allocation-and-deallocation-across-dll-boundaries – Kent Aug 24 '12 at 05:23

1 Answers1

0

You can export a kind of free function from DLL and call it from the destructor of smart_ref. This is how COM and similar technologies work.

Sergey K.
  • 24,894
  • 13
  • 106
  • 174
  • I am still puzzled by this. COM wouldn't work correctly if some process deliberately unloads the DLL without proper cleaning (i.e. calling decref functions etc) Main still would have full reference after FreeLibrary(hmodule). How can the memory be safeguarded against this so that full smart-refs returns false on a isValid check? – user1362700 Jan 17 '14 at 10:48