Click here to Skip to main content
Click here to Skip to main content

Implementing the __FUNCTION__ Macro in VC++ 6.0

, 27 Mar 2006 CPOL
Rate this:
Please Sign up or sign in to vote.
Tired of searching for the __FUNCTION__ macro to debug your apps in VC++ 6.0? Here's a little overkill to replicate it
Sample Image - xtrace.jpg


Ok, so you're stuck with VC++ 6.0 (can't upgrade to .NET) but you need that nifty __FUNCTION__ macro for your debug sessions or, as in my case for debug session logging, and you Googled for it all over the world (including China) to get such ambiguous answers as "I'm a 100% sure that VC++ 6.0 implements it" and "get .NET you @$$#ole!". So you're outdated, sour and two steps shy of self-suicide (what an oxymoron).

Enter The Code Project (where you should have looked in the first place) to find that there's a whole world of portable executable image help APIs and symbols and processes and threads you really never cared about before, and... oh well.

There's also a whole debug section on CodeProject I didn't know about. Now get to Zoltan Csizmadia's article in which he implements the Extended Trace functions. My version is a downsized one from that of Csizmadia's, in which I only retrieve function names (to the point of omitting class names and arguments) to produce the kind of output shown in the figure. Granted, the code looks like overkill to achieve what .NET (VC++ 7.0 to my understanding) does intrinsically, but it works for me, and I bet you something not too worthy that intrinsically means going through a similar image-symbol-scanning process. In any case, I learned a lot about PEs, the Image Help API, debugging and a lot of stuff I wasn't really looking for, and ultimately, I got away with what I wanted to do.

To learn about all that stuff, get to the debug section of The Code Project, for I will not go into it in this article. The code is almost self-explanatory and fairly commented; just add the two files (header and CPP) to your project, add the #include directives at the proper places, and call InitSymInfo() upon start, and KillSymInfo() before exiting; use the __FUNCTION__ macro anywhere in your code; it returns a (temp) LPCTSTR you can use as you like.

Zoltan's version does retrieve the full function prototype, its arguments and their values; if you need all that or just want to check it out, click here.

Thank Zoltan and enjoy!


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

hector [.j.] rivas
Software Developer (Senior) Code Authority, Inc.
United States United States
Pride in craftsmanship is my new thing.
Follow on   LinkedIn

Comments and Discussions

QuestionDoes not work for me. StackWalk() fails with error code: error_partial_copy. Pinmembersondhi_chakraborty11-Feb-12 19:48 
GeneralRe: callStack.AddrFrame.Offset = 0 PinmemberMYeager5630-Sep-10 10:34 
QuestionSymGetSymFromAddr in GetFuncInfo fails due to GetCurrentProcess returning 0xffffffff PinmemberX-treem18-Aug-06 5:51 
AnswerRe: SymGetSymFromAddr in GetFuncInfo fails due to GetCurrentProcess returning 0xffffffff PinmemberTor2k22-Aug-06 7:14 
GeneralRe: SymGetSymFromAddr in GetFuncInfo fails due to GetCurrentProcess returning 0xffffffff Pinmembercavalierfire22-May-08 23:53 
Generalmy modification Pinmembercomealong25-Jul-06 21:07 
QuestionRe: my modification Pinmemberchris17526-Jul-06 3:19 
AnswerRe: my modification Pinmembercomealong26-Jul-06 21:21 
GeneralRe: my modification PinmemberTor2k29-Jul-06 9:24 
Question__FUNCTION__ not working in console debug mode Pinmemberchris1756-Jul-06 5:13 
AnswerRe: __FUNCTION__ not working in console debug mode Pinmemberjuls337-Jul-06 6:25 
GeneralRe: __FUNCTION__ not working in console debug mode Pinmemberdasdasa27-Aug-06 21:05 
GeneralRe: __FUNCTION__ not working in console debug mode Pinmemberconrad Braam14-Jan-08 6:17 
Question__FUNCTION__ working in Release Mode? Pinmemberchris1753-Jul-06 3:37 
AnswerRe: __FUNCTION__ working in Release Mode? PinmemberGraham Reeds7-Jul-06 4:52 
QuestionRe: __FUNCTION__ working in Release Mode? Pinmemberchris1757-Jul-06 4:56 
AnswerRe: __FUNCTION__ working in Release Mode? [modified] PinmemberTor2k12-Jul-06 15:44 
AnswerRe: __FUNCTION__ working in Release Mode? Pinmemberdasdasa25-Aug-06 2:55 
GeneralRe: __FUNCTION__ working in Release Mode? Pinmemberdasdasa25-Aug-06 3:05 
QuestionQuestion about UnDecorateSymbolName Flags Pinmemberchris17530-Jun-06 2:32 
AnswerRe: Question about UnDecorateSymbolName Flags PinmemberTor2k12-Jul-06 16:19 
GeneralcallStack.AddrFrame.Offset = 0 PinmemberRick Crone2-Mar-06 6:28 
GeneralRe: callStack.AddrFrame.Offset = 0 PinmemberTor2k10-Mar-06 16:10 
GeneralRe: callStack.AddrFrame.Offset = 0 PinmemberGraham Reeds7-Jul-06 5:11 
GeneralRe: callStack.AddrFrame.Offset = 0 PinmemberTor2k12-Jul-06 16:33 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150414.1 | Last Updated 27 Mar 2006
Article Copyright 2006 by hector [.j.] rivas
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid