How to make a C ++ DLL call my overloaded global new operator?

I overloaded the global new / delete (and new [] / delete []) to populate and check protected blocks. Works great. Now I am referring to the C ++ DLL, passing instances of STL-Container that are populated or modified by the DLL. When I destroy these containers, I encounter an error because they were not distributed using my overloaded new operator, and vice versa, the DLL generates errors when releasing container elements that were created using my overloaded new operator.

How can I get a dll to call my new statement? For some DLLs I have sources, for others I do not have them.

There should be a general approach, as the Visual Studio Runtime MSVCP * .DLL DLL files invoke my overloaded statements. How can I get other dlls to call my statements as well?

a) Having sources for a DLL? and check b) No sources for DLL?

+3
source share
2 answers

for dlls that you can compile, you can force them to call overloaded methods with

  • make sure the calling code contains a header that identifies your overloads.
  • export these overloads from your DLL by specifying them in the export file

here is the export (using malformed names, never found another way to do this) for new / delete / new [] / delete [], throwing versions.

x86:

EXPORTS
  ??2@YAPAXI@Z
  ??3@YAXPAX@Z
  ??_U@YAPAXI@Z
  ??_V@YAXPAX@Z

64:

EXPORTS
  ??2@YAPEAX_K@Z
  ??3@YAXPEAX@Z
  ??_U@YAPEAX_K@Z
  ??_V@YAXPEAX@Z

, DLL, ( , , ); , , , , crt .

, DLL , dll /delete. , /, . , , STL, ; , , DLL, .

+2

, / DLL , exe DLL .

, , , , - , , , .

0

Source: https://habr.com/ru/post/1767504/


All Articles