1 ////////////////////////////////////////////////////////////////////////////////
3 // Visual Leak Detector - CRT and MFC IAT Patch Functions Header
4 // Copyright (c) 2009 Dan Moulding
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 // See COPYING.txt for the full terms of the GNU Lesser General Public License.
22 ////////////////////////////////////////////////////////////////////////////////
28 "This header should only be included by Visual Leak Detector when building it from source. \
29 Applications should never include this header."
33 extern __declspec(dllexport) VisualLeakDetector vld;
35 #define TEMPLATE_HEADER \
36 template<wchar_t const *crtddll, wchar_t const *mfcddll, wchar_t const *mfcuddll,\
37 char const *crtd_vector_new_name, char const *crtd_vector_new_dbg_name,\
38 char const *crtd_scalar_new_name, char const *crtd_scalar_new_dbg_name,\
39 int mfcd_vector_new_ordinal, int mfcd_vector_new_dbg_4p_ordinal, int mfcd_vector_new_dbg_3p_ordinal,\
40 int mfcd_scalar_new_ordinal, int mfcd_scalar_new_dbg_4p_ordinal, int mfcd_scalar_new_dbg_3p_ordinal,\
41 int mfcud_vector_new_ordinal, int mfcud_vector_new_dbg_4p_ordinal, int mfcud_vector_new_dbg_3p_ordinal,\
42 int mfcud_scalar_new_ordinal, int mfcud_scalar_new_dbg_4p_ordinal, int mfcud_scalar_new_dbg_3p_ordinal>
44 #define TEMPLATE_ARGS \
45 crtddll, mfcddll, mfcuddll,\
46 crtd_vector_new_name, crtd_vector_new_dbg_name,\
47 crtd_scalar_new_name, crtd_scalar_new_dbg_name,\
48 mfcd_vector_new_ordinal, mfcd_vector_new_dbg_4p_ordinal, mfcd_vector_new_dbg_3p_ordinal,\
49 mfcd_scalar_new_ordinal, mfcd_scalar_new_dbg_4p_ordinal, mfcd_scalar_new_dbg_3p_ordinal,\
50 mfcud_vector_new_ordinal, mfcud_vector_new_dbg_4p_ordinal, mfcud_vector_new_dbg_3p_ordinal,\
51 mfcud_scalar_new_ordinal, mfcud_scalar_new_dbg_4p_ordinal, mfcud_scalar_new_dbg_3p_ordinal
57 static void* __cdecl crtd__calloc_dbg (size_t num, size_t size, int type, char const *file, int line);
58 static void* __cdecl crtd__malloc_dbg (size_t size, int type, const char *file, int line);
59 static void* __cdecl crtd__realloc_dbg (void *mem, size_t size, int type, char const *file, int line);
60 static void* __cdecl crtd__scalar_new_dbg (size_t size, int type, char const *file, int line);
61 static void* __cdecl crtd__vector_new_dbg (size_t size, int type, char const *file, int line);
62 static void* __cdecl crtd_calloc (size_t num, size_t size);
63 static void* __cdecl crtd_malloc (size_t size);
64 static void* __cdecl crtd_realloc (void *mem, size_t size);
65 static void* __cdecl crtd_scalar_new (size_t size);
66 static void* __cdecl crtd_vector_new (size_t size);
68 template<char const *procname>
69 static void* __cdecl crtd_new_dbg (SIZE_T fp, size_t size, int type, char const *file, int line);
70 template<char const *procname>
71 static void* __cdecl crtd_new (SIZE_T fp, size_t size);
73 static void* __cdecl mfcd_vector_new (size_t size);
74 static void* __cdecl mfcd__vector_new_dbg_4p (size_t size, int type, char const *file, int line);
75 static void* __cdecl mfcd__vector_new_dbg_3p (size_t size, char const *file, int line);
76 static void* __cdecl mfcd_scalar_new (size_t size);
77 static void* __cdecl mfcd__scalar_new_dbg_4p (size_t size, int type, char const *file, int line);
78 static void* __cdecl mfcd__scalar_new_dbg_3p (size_t size, char const *file, int line);
79 static void* __cdecl mfcud_vector_new (size_t size);
80 static void* __cdecl mfcud__vector_new_dbg_4p (size_t size, int type, char const *file, int line);
81 static void* __cdecl mfcud__vector_new_dbg_3p (size_t size, char const *file, int line);
82 static void* __cdecl mfcud_scalar_new (size_t size);
83 static void* __cdecl mfcud__scalar_new_dbg_4p (size_t size, int type, char const *file, int line);
84 static void* __cdecl mfcud__scalar_new_dbg_3p (size_t size, char const *file, int line);
86 template<wchar_t const *mfcdll, int ordinal>
87 static void* __cdecl mfcd_new_dbg (SIZE_T fp, size_t size, int type, char const *file, int line);
88 template<wchar_t const *mfcdll, int ordinal>
89 static void* __cdecl mfcd_new_dbg (SIZE_T fp, size_t size, char const *file, int line);
90 template<wchar_t const *mfcdll, int ordinal>
91 static void* __cdecl mfcd_new (SIZE_T fp, size_t size);
95 ////////////////////////////////////////////////////////////////////////////////
99 ////////////////////////////////////////////////////////////////////////////////
101 // crtd__calloc_dbg - Calls to _calloc_dbg from msvcrXXd.dll are patched
102 // through to this function.
104 // - mem (IN): Pointer to the memory block to be reallocated.
106 // - size (IN): The size, in bytes, of the memory block to be allocated.
108 // - type (IN): The CRT "use type" of the block to be allocated.
110 // - file (IN): The name of the file from which this function is being called.
112 // - line (IN): The line number, in the above file, at which this function is
117 // Returns the value returned by _calloc_dbg.
120 void* CrtMfcPatch<TEMPLATE_ARGS>::crtd__calloc_dbg (size_t num,
126 static _calloc_dbg_t pcrtxxd__calloc_dbg = NULL;
133 if (pcrtxxd__calloc_dbg == NULL) {
134 // This is the first call to this function. Link to the real
136 msvcrxxd = GetModuleHandle(crtddll);
137 pcrtxxd__calloc_dbg = (_calloc_dbg_t)GetProcAddress(msvcrxxd, "_calloc_dbg");
140 return vld.__calloc_dbg(pcrtxxd__calloc_dbg, fp, num, size, type, file, line);
143 // crtd__malloc_dbg - Calls to _malloc_dbg from msvcrXXd.dll are patched
144 // through to this function.
146 // - size (IN): The size, in bytes, of the memory block to be allocated.
148 // - type (IN): The CRT "use type" of the block to be allocated.
150 // - file (IN): The name of the file from which this function is being called.
152 // - line (IN): The line number, in the above file, at which this function is
157 // Returns the value returned by _malloc_dbg.
160 void* CrtMfcPatch<TEMPLATE_ARGS>::crtd__malloc_dbg (size_t size,
165 static _malloc_dbg_t pcrtxxd__malloc_dbg = NULL;
172 if (pcrtxxd__malloc_dbg == NULL) {
173 // This is the first call to this function. Link to the real
175 msvcrxxd = GetModuleHandle(crtddll);
176 pcrtxxd__malloc_dbg = (_malloc_dbg_t)GetProcAddress(msvcrxxd, "_malloc_dbg");
179 return vld.__malloc_dbg(pcrtxxd__malloc_dbg, fp, size, type, file, line);
182 // crtd__realloc_dbg - Calls to _realloc_dbg from msvcrXXd.dll are patched
183 // through to this function.
185 // - mem (IN): Pointer to the memory block to be reallocated.
187 // - size (IN): The size of the memory block to reallocate.
189 // - type (IN): The CRT "use type" of the block to be reallocated.
191 // - file (IN): The name of the file from which this function is being called.
193 // - line (IN): The line number, in the above file, at which this function is
198 // Returns the value returned by _realloc_dbg.
201 void* CrtMfcPatch<TEMPLATE_ARGS>::crtd__realloc_dbg (void *mem,
207 static _realloc_dbg_t pcrtxxd__realloc_dbg = NULL;
214 if (pcrtxxd__realloc_dbg == NULL) {
215 // This is the first call to this function. Link to the real
217 msvcrxxd = GetModuleHandle(crtddll);
218 pcrtxxd__realloc_dbg = (_realloc_dbg_t)GetProcAddress(msvcrxxd, "_realloc_dbg");
221 return vld.__realloc_dbg(pcrtxxd__realloc_dbg, fp, mem, size, type, file, line);
224 // crtd__scalar_new_dbg - Calls to the CRT's debug scalar new operator from
225 // msvcrXXd.dll are patched through to this function.
227 // - size (IN): The size, in bytes, of the memory block to be allocated.
229 // - type (IN): The CRT "use type" of the block to be allocated.
231 // - file (IN): The name of the file from which this function is being called.
233 // - line (IN): The line number, in the above file, at which this function is
238 // Returns the value returned by the CRT debug scalar new operator.
241 void* CrtMfcPatch<TEMPLATE_ARGS>::crtd__scalar_new_dbg (size_t size,
249 return crtd_new_dbg<crtd_scalar_new_dbg_name>(fp, size, type, file, line);
252 // crtd__vector_new_dbg - Calls to the CRT's debug vector new operator from
253 // msvcrXXd.dll are patched through to this function.
255 // - size (IN): The size, in bytes, of the memory block to be allocated.
257 // - type (IN): The CRT "use type" of the block to be allocated.
259 // - file (IN): The name of the file from which this function is being called.
261 // - line (IN): The line number, in the above file, at which this function is
266 // Returns the value returned by the CRT debug vector new operator.
269 void* CrtMfcPatch<TEMPLATE_ARGS>::crtd__vector_new_dbg (size_t size,
277 return crtd_new_dbg<crtd_vector_new_dbg_name>(fp, size, type, file, line);
280 // crtd_calloc - Calls to calloc from msvcrXXd.dll are patched through to
283 // - dll (IN): The name of the dll
285 // - num (IN): The number of blocks, of size 'size', to be allocated.
287 // - size (IN): The size, in bytes, of the memory block to be allocated.
291 // Returns the valued returned from calloc.
294 void* CrtMfcPatch<TEMPLATE_ARGS>::crtd_calloc (size_t num, size_t size)
296 static calloc_t pcrtxxd_calloc = NULL;
303 if (pcrtxxd_calloc == NULL) {
304 // This is the first call to this function. Link to the real malloc.
305 msvcrxxd = GetModuleHandle(crtddll);
306 pcrtxxd_calloc = (calloc_t)GetProcAddress(msvcrxxd, "calloc");
309 return vld._calloc(pcrtxxd_calloc, fp, num, size);
312 // crtd_malloc - Calls to malloc from msvcrXXd.dll are patched through to
315 // - dll (IN): The name of the dll
317 // - size (IN): The size, in bytes, of the memory block to be allocated.
321 // Returns the valued returned from malloc.
324 void* CrtMfcPatch<TEMPLATE_ARGS>::crtd_malloc (size_t size)
326 static malloc_t pcrtxxd_malloc = NULL;
333 if (pcrtxxd_malloc == NULL) {
334 // This is the first call to this function. Link to the real malloc.
335 msvcrxxd = GetModuleHandle(crtddll);
336 pcrtxxd_malloc = (malloc_t)GetProcAddress(msvcrxxd, "malloc");
339 return vld._malloc(pcrtxxd_malloc, fp, size);
342 // crtd_realloc - Calls to realloc from msvcrXXd.dll are patched through to
345 // - dll (IN): The name of the dll
347 // - mem (IN): Pointer to the memory block to reallocate.
349 // - size (IN): Size of the memory block to reallocate.
353 // Returns the value returned from realloc.
356 void* CrtMfcPatch<TEMPLATE_ARGS>::crtd_realloc (void *mem, size_t size)
358 static realloc_t pcrtxxd_realloc = NULL;
365 if (pcrtxxd_realloc == NULL) {
366 // This is the first call to this function. Link to the real realloc.
367 msvcrxxd = GetModuleHandle(crtddll);
368 pcrtxxd_realloc = (realloc_t)GetProcAddress(msvcrxxd, "realloc");
371 return vld._realloc(pcrtxxd_realloc, fp, mem, size);
374 // crtd_scalar_new - Calls to the CRT's scalar new operator from msvcrXXd.dll
375 // are patched through to this function.
377 // - size (IN): The size, in bytes, of the memory block to be allocated.
381 // Returns the value returned by the CRT scalar new operator.
384 void* CrtMfcPatch<TEMPLATE_ARGS>::crtd_scalar_new (size_t size)
389 return crtd_new<crtd_scalar_new_name>(fp, size);
392 // crtd_vector_new - Calls to the CRT's vector new operator from msvcrXXd.dll
393 // are patched through to this function.
395 // - size (IN): The size, in bytes, of the memory block to be allocated.
399 // Returns the value returned by the CRT vector new operator.
402 void* CrtMfcPatch<TEMPLATE_ARGS>::crtd_vector_new (size_t size)
407 return crtd_new<crtd_vector_new_name>(fp, size);
410 // crtd_new_dbg - A template function for implementation of patch functions to
411 // the CRT's debug new operator from msvcrXXd.dll
413 // - procname (IN): The debug new operator's name
415 // - fp (IN): Frame pointer from the call that initiated this allocation.
417 // - size (IN): The size, in bytes, of the memory block to be allocated.
419 // - type (IN): The CRT "use type" of the block to be allocated.
421 // - file (IN): The name of the file from which this function is being called.
423 // - line (IN): The line number, in the above file, at which this function is
428 // Returns the value returned by the CRT debug new operator.
431 template<char const *procname>
432 void* CrtMfcPatch<TEMPLATE_ARGS>::crtd_new_dbg (SIZE_T fp,
438 static new_dbg_crt_t pcrtxxd_new_dbg = NULL;
442 if (pcrtxxd_new_dbg == NULL) {
443 // This is the first call to this function. Link to the real CRT debug
445 msvcrxxd = GetModuleHandle(crtddll);
446 pcrtxxd_new_dbg = (new_dbg_crt_t)GetProcAddress(msvcrxxd, procname);
449 return vld.new_dbg_crt(pcrtxxd_new_dbg, fp, size, type, file, line);
452 // crt_new - A template function for implementing patch functions to the
453 // CRT's new operator from msvcrXXd.dll
455 // - dll (IN): The name of the dll
457 // - procname (IN): The debug new operator's name
459 // - size (IN): The size, in bytes, of the memory block to be allocated.
463 // Returns the value returned by the CRT new operator.
466 template<char const *procname>
467 void* CrtMfcPatch<TEMPLATE_ARGS>::crtd_new (SIZE_T fp, size_t size)
469 static new_t pcrtxxd_scalar_new = NULL;
473 if (pcrtxxd_scalar_new == NULL) {
474 // This is the first call to this function. Link to the real CRT new
476 msvcrxxd = GetModuleHandle(crtddll);
477 pcrtxxd_scalar_new = (new_t)GetProcAddress(msvcrxxd, procname);
480 return vld._new(pcrtxxd_scalar_new, fp, size);
483 ////////////////////////////////////////////////////////////////////////////////
487 ////////////////////////////////////////////////////////////////////////////////
489 // mfcd__scalar_new_dbg_3p - Calls to the MFC debug scalar new operator from
490 // mfcXXd.dll are patched through to this function.
492 // - size (IN): The size, in bytes, of the memory block to be allocated.
494 // - type (IN): The "use type" of the block to be allocated.
496 // - file (IN): The name of the file from which this function is being called.
498 // - line (IN): The line number, in the above file, at which this function is
503 // Returns the value returned by the MFC debug scalar new operator.
506 void* CrtMfcPatch<TEMPLATE_ARGS>::mfcd__scalar_new_dbg_4p (size_t size,
514 return mfcd_new_dbg<mfcddll, mfcd_scalar_new_dbg_4p_ordinal>
515 (fp, size, type, file, line);
518 // mfcd__scalar_new_dbg_3p - Calls to the MFC debug scalar new operator from
519 // mfcXXd.dll are patched through to this function.
521 // - size (IN): The size, in bytes, of the memory block to be allocated.
523 // - file (IN): The name of the file from which this function is being called.
525 // - line (IN): The line number, in the above file, at which this function is
530 // Returns the value returned by the MFC debug scalar new operator.
533 void* CrtMfcPatch<TEMPLATE_ARGS>::mfcd__scalar_new_dbg_3p (size_t size,
540 return mfcd_new_dbg<mfcddll, mfcd_scalar_new_dbg_3p_ordinal>
541 (fp, size, file, line);
544 // mfcd__vector_new_dbg_4p - Calls to the MFC debug vector new operator from
545 // mfcXXd.dll are patched through to this function.
547 // - size (IN): The size, in bytes, of the memory block to be allocated.
549 // - type (IN): The "use type" of the block to be allocated.
551 // - file (IN): The name of the file from which this function is being called.
553 // - line (IN): The line number, in the above file, at which this function is
558 // Returns the value returned by the MFC debug vector new operator.
561 void* CrtMfcPatch<TEMPLATE_ARGS>::mfcd__vector_new_dbg_4p (size_t size,
569 return mfcd_new_dbg<mfcddll, mfcd_vector_new_dbg_4p_ordinal>
570 (fp, size, type, file, line);
573 // mfcd__vector_new_dbg_3p - Calls to the MFC debug vector new operator from
574 // mfcXXd.dll are patched through to this function.
576 // - size (IN): The size, in bytes, of the memory block to be allocated.
578 // - file (IN): The name of the file from which this function is being called.
580 // - line (IN): The line number, in the above file, at which this function is
585 // Returns the value returned by the MFC debug vector new operator.
588 void* CrtMfcPatch<TEMPLATE_ARGS>::mfcd__vector_new_dbg_3p (size_t size,
595 return mfcd_new_dbg<mfcddll, mfcd_vector_new_dbg_3p_ordinal>
596 (fp, size, file, line);
599 // mfcd_scalar_new - Calls to the MFC scalar new operator from mfcXXd.dll are
600 // patched through to this function.
602 // - size (IN): The size, in bytes, of the memory block to be allocated.
606 // Returns the value returned by the MFC scalar new operator.
609 void* CrtMfcPatch<TEMPLATE_ARGS>::mfcd_scalar_new (size_t size)
614 return mfcd_new<mfcddll, mfcd_scalar_new_ordinal>(fp, size);
617 // mfcd_vector_new - Calls to the MFC vector new operator from mfcXXd.dll are
618 // patched through to this function.
620 // - size (IN): The size, in bytes, of the memory block to be allocated.
624 // Returns the value returned by the MFC vector new operator.
627 void* CrtMfcPatch<TEMPLATE_ARGS>::mfcd_vector_new (size_t size)
632 return mfcd_new<mfcddll, mfcd_vector_new_ordinal>(fp, size);
635 // mfcud__scalar_new_dbg_4p - Calls to the MFC debug scalar new operator from
636 // mfcXXud.dll are patched through to this function.
638 // - size (IN): The size, in bytes, of the memory block to be allocated.
640 // - type (IN): The "use type" of the block to be allocated.
642 // - file (IN): The name of the file from which this function is being called.
644 // - line (IN): The line number, in the above file, at which this function is
649 // Returns the value returned by the MFC debug scalar new operator.
652 void* CrtMfcPatch<TEMPLATE_ARGS>::mfcud__scalar_new_dbg_4p (size_t size,
660 return mfcd_new_dbg<mfcuddll, mfcud_scalar_new_dbg_4p_ordinal>
661 (fp, size, type, file, line);
664 // mfcud__scalar_new_dbg_3p - Calls to the MFC debug scalar new operator from
665 // mfcXXud.dll are patched through to this function.
667 // - size (IN): The size, in bytes, of the memory block to be allocated.
669 // - file (IN): The name of the file from which this function is being called.
671 // - line (IN): The line number, in the above file, at which this function is
676 // Returns the value returned by the MFC debug scalar new operator.
679 void* CrtMfcPatch<TEMPLATE_ARGS>::mfcud__scalar_new_dbg_3p (size_t size,
686 return mfcd_new_dbg<mfcuddll, mfcud_scalar_new_dbg_3p_ordinal>
687 (fp, size, file, line);
690 // mfcud__vector_new_dbg_4p - Calls to the MFC debug vector new operator from
691 // mfcXXud.dll are patched through to this function.
693 // - size (IN): The size, in bytes, of the memory block to be allocated.
695 // - type (IN): The "use type" of the block to be allocated.
697 // - file (IN): The name of the file from which this function is being called.
699 // - line (IN): The line number, in the above file, at which this function is
704 // Returns the value returned by the MFC debug vector new operator.
707 void* CrtMfcPatch<TEMPLATE_ARGS>::mfcud__vector_new_dbg_4p (size_t size,
715 return mfcd_new_dbg<mfcuddll, mfcud_vector_new_dbg_4p_ordinal>
716 (fp, size, type, file, line);
719 // mfcud__vector_new_dbg_3p - Calls to the MFC debug vector new operator from
720 // mfcXXud.dll are patched through to this function.
722 // - size (IN): The size, in bytes, of the memory block to be allocated.
724 // - file (IN): The name of the file from which this function is being called.
726 // - line (IN): The line number, in the above file, at which this function is
731 // Returns the value returned by the MFC debug vector new operator.
734 void* CrtMfcPatch<TEMPLATE_ARGS>::mfcud__vector_new_dbg_3p (size_t size,
741 return mfcd_new_dbg<mfcuddll, mfcud_vector_new_dbg_3p_ordinal>
742 (fp, size, file, line);
745 // mfcud_scalar_new - Calls to the MFC scalar new operator from mfcXXud.dll are
746 // patched through to this function.
748 // - size (IN): The size, in bytes, of the memory block to be allocated.
752 // Returns the value returned by the MFC scalar new operator.
755 void* CrtMfcPatch<TEMPLATE_ARGS>::mfcud_scalar_new (size_t size)
760 return mfcd_new<mfcuddll, mfcud_scalar_new_ordinal>(fp, size);
763 // mfcud_vector_new - Calls to the MFC vector new operator from mfcXXud.dll are
764 // patched through to this function.
766 // - size (IN): The size, in bytes, of the memory block to be allocated.
770 // Returns the value returned by the MFC vector new operator.
773 void* CrtMfcPatch<TEMPLATE_ARGS>::mfcud_vector_new (size_t size)
778 return mfcd_new<mfcuddll, mfcud_vector_new_ordinal>(fp, size);
781 // mfcd_new_dbg - A generic function for implementing patch functions to the MFC
782 // debug new operators:
783 // void* __cdecl operator new[](size_t size, int type, char const *file, int line)
784 // void* __cdecl operator new(size_t size, int type, char const *file, int line)
786 // - mfcdll (IN): The name of the MFC DLL
788 // - ordinal (IN): The debug new operator's ordinal value
790 // - type (IN): The "use type" of the block to be allocated.
792 // - size (IN): The size, in bytes, of the memory block to be allocated.
794 // - file (IN): The name of the file from which this function is being called.
796 // - line (IN): The line number, in the above file, at which this function is
801 // Returns the value returned by the MFC debug new operator.
804 template<wchar_t const *mfcdll, int ordinal>
805 void* CrtMfcPatch<TEMPLATE_ARGS>::mfcd_new_dbg (SIZE_T fp,
811 static new_dbg_crt_t pmfcxxd__new_dbg = NULL;
815 if (pmfcxxd__new_dbg == NULL) {
816 // This is the first call to this function. Link to the real MFC debug
818 mfcxxd = GetModuleHandle(mfcdll);
819 pmfcxxd__new_dbg = (new_dbg_crt_t)GetProcAddress(mfcxxd, (LPCSTR)ordinal);
822 return vld.new_dbg_mfc(pmfcxxd__new_dbg, fp, size, type, file, line);
825 // mfcd_new_dbg - A generic function for implementing patch functions to the MFC
826 // debug new operators:
827 // void* __cdecl operator new[](size_t size, char const *file, int line)
828 // void* __cdecl operator new(size_t size, char const *file, int line)
830 // - mfcdll (IN): The name of the MFC DLL
832 // - ordinal (IN): The debug new operator's ordinal value
834 // - size (IN): The size, in bytes, of the memory block to be allocated.
836 // - file (IN): The name of the file from which this function is being called.
838 // - line (IN): The line number, in the above file, at which this function is
843 // Returns the value returned by the MFC debug new operator.
846 template<wchar_t const *mfcdll, int ordinal>
847 void* CrtMfcPatch<TEMPLATE_ARGS>::mfcd_new_dbg (SIZE_T fp,
852 static new_dbg_mfc_t pmfcxxd__new_dbg = NULL;
856 if (pmfcxxd__new_dbg == NULL) {
857 // This is the first call to this function. Link to the real MFC debug
859 mfcxxd = GetModuleHandle(mfcdll);
860 pmfcxxd__new_dbg = (new_dbg_mfc_t)GetProcAddress(mfcxxd, (LPCSTR)ordinal);
863 return vld.new_dbg_mfc(pmfcxxd__new_dbg, fp, size, file, line);
866 // mfcd_new - A generic function for implementing patch functions to the MFC new
869 // - mfcdll (IN): The name of the MFC DLL
871 // - ordinal (IN): The new operator's ordinal value
873 // - size (IN): The size, in bytes, of the memory block to be allocated.
877 // Returns the value returned by the MFC new operator.
880 template<wchar_t const *mfcdll, int ordinal>
881 void* CrtMfcPatch<TEMPLATE_ARGS>::mfcd_new (SIZE_T fp, size_t size)
883 static new_t pmfcxxd_new = NULL;
887 if (pmfcxxd_new == NULL) {
888 // This is the first call to this function. Link to the real CRT new
890 mfcxxd = GetModuleHandle(mfcdll);
891 pmfcxxd_new = (new_t)GetProcAddress(mfcxxd, (LPCSTR)ordinal);
894 return vld._new(pmfcxxd_new, fp, size);
897 #undef TEMPLATE_HEADER
900 const extern char scalar_new_dbg_name[] = "??2@YAPAXIHPBDH@Z";
901 const extern char vector_new_dbg_name[] = "??_U@YAPAXIHPBDH@Z";
902 const extern char scalar_new_name[] = "??2@YAPAXI@Z";
903 const extern char vector_new_name[] = "??_U@YAPAXI@Z";
904 const extern wchar_t msvcrtd_dll[] = L"msvcrtd.dll";
905 const extern wchar_t mfc42d_dll[] = L"mfc42d.dll";
906 const extern wchar_t mfc42ud_dll[] = L"mfc42ud.dll";
907 const extern wchar_t msvcr70d_dll[] = L"msvcr70d.dll";
908 const extern wchar_t mfc70d_dll[] = L"mfc70d.dll";
909 const extern wchar_t mfc70ud_dll[] = L"mfc70ud.dll";
910 const extern wchar_t msvcr71d_dll[] = L"msvcr71d.dll";
911 const extern wchar_t mfc71d_dll[] = L"mfc71d.dll";
912 const extern wchar_t mfc71ud_dll[] = L"mfc71ud.dll";
913 const extern wchar_t msvcr80d_dll[] = L"msvcr80d.dll";
914 const extern wchar_t mfc80d_dll[] = L"mfc80d.dll";
915 const extern wchar_t mfc80ud_dll[] = L"mfc80ud.dll";
916 const extern wchar_t msvcr90d_dll[] = L"msvcr90d.dll";
917 const extern wchar_t mfc90d_dll[] = L"mfc90d.dll";
918 const extern wchar_t mfc90ud_dll[] = L"mfc90ud.dll";
919 const extern wchar_t msvcr100d_dll[] = L"msvcr100d.dll";
920 const extern wchar_t mfc100d_dll[] = L"mfc100d.dll";
921 const extern wchar_t mfc100ud_dll[] = L"mfc100ud.dll";
924 typedef CrtMfcPatch<msvcrtd_dll, mfc42d_dll, mfc42ud_dll,
925 vector_new_name, vector_new_dbg_name,
926 scalar_new_name, scalar_new_dbg_name,
927 0, 0, 0, 711, 712, 714,
928 0, 0, 0, 711, 712, 714>
930 // Visual Studio .NET 2002
931 typedef CrtMfcPatch<msvcr70d_dll, mfc70d_dll, mfc70ud_dll,
932 vector_new_name, vector_new_dbg_name,
933 scalar_new_name, scalar_new_dbg_name,
934 257, 258, 259, 832, 833, 834,
935 258, 259, 260, 833, 834, 835>
937 // Visual Studio .NET 2003
938 typedef CrtMfcPatch<msvcr71d_dll, mfc71d_dll, mfc71ud_dll,
939 vector_new_name, vector_new_dbg_name,
940 scalar_new_name, scalar_new_dbg_name,
941 267, 268, 269, 893, 894, 895,
942 267, 268, 269, 893, 894, 895>
944 // Visual Studio 2005
945 typedef CrtMfcPatch<msvcr80d_dll, mfc80d_dll, mfc80ud_dll,
946 vector_new_name, vector_new_dbg_name,
947 scalar_new_name, scalar_new_dbg_name,
948 267, 268, 269, 893, 894, 895,
949 267, 268, 269, 893, 894, 895>
951 // Visual Studio 2008
952 typedef CrtMfcPatch<msvcr90d_dll, mfc90d_dll, mfc90ud_dll,
953 vector_new_name, vector_new_dbg_name,
954 scalar_new_name, scalar_new_dbg_name,
955 267, 268, 269, 931, 932, 933,
956 267, 268, 269, 935, 936, 937>
959 // Visual Studio 2010
960 typedef CrtMfcPatch<msvcr100d_dll, mfc100d_dll, mfc100ud_dll,
961 vector_new_name, vector_new_dbg_name,
962 scalar_new_name, scalar_new_dbg_name,
963 267, 268, 269, 1405, 1406, 1407,
964 267, 268, 269, 1412, 1413, 1414>