_CrtSetReportHook issues C/C++

Associate
Joined
22 Nov 2005
Posts
319
Location
Alnwick, Northumberland
I have created my own memory management class which basically detects where there are memory leaks in the program. To improve this further i wanted to create my own report hook, so ive constructed the function, just like told on the msdn:
int YourReportHook( int reportType, char *message, int *returnValue );

and ive called the set hook method
_CrtSetReportHook(YoutReportHook)

and when compiling i get this error :
error C2664: '_CrtSetReportHook' : cannot convert parameter 1 from 'int (int,char *,int *)' to 'int (__cdecl *)(int,char *,int *)'
None of the functions with this name in scope match the target type

ive just followed what was on the msdn and this wont compile! any ideas?
Edit/Delete Message
 
Not sure as I haven't actually tried this but try adding __stdcall before the function prototype for your report hook.

so instead of
"int myReportHook_(blaaa, blaaa, blaaa, ... )" it's
"int __stdcall myReportHook_(blaaa, blaaa, blaaa, ... )"

Hope this helps

Edit: Even though that MSDN example doesn't specify __stdcall, the reason that this may be needed is because that example is written in C, not C++. By default, all C++ function prototypes are declared in the type system using a more modern technique (that supports classes and other C++ specific stuff). __stdcall tells the compiler that you want to use the old-style C function prototype system.
 
Last edited:
Laurio said:
I have created my own memory management class which basically detects where there are memory leaks in the program. To improve this further i wanted to create my own report hook, so ive constructed the function, just like told on the msdn:
int YourReportHook( int reportType, char *message, int *returnValue );

and ive called the set hook method
_CrtSetReportHook(YoutReportHook)

and when compiling i get this error :
error C2664: '_CrtSetReportHook' : cannot convert parameter 1 from 'int (int,char *,int *)' to 'int (__cdecl *)(int,char *,int *)'
None of the functions with this name in scope match the target type

ive just followed what was on the msdn and this wont compile! any ideas?
Edit/Delete Message

Are you compiling your hook code in 'C' mode, and declaring it as such with extern "c" declarations?
 
i tried placing _cdecl infront of function name but this made no difference, i found posts on internet which said to do that, but didnt make a difference.

I have however just realised that i may not be able to use this method, because it is a member function, and the only way to get rid of compliation error and use the hook is to make it a static method, but i dont want it to be static as i have member pointers i need to call in this method.

yes i did try declaring it as extern "c" but that made no difference whatsoever.

any further ideas?
 
Back
Top Bottom