|
__FILE__ is replaced (during compilation) with the name of the file
__LINE__ is replaced (during compilation) with the current line
But how do I get the name of the function I'm just in?
I'm using VisualStudio 6.0, programming in pure C. I want to call a function writing text to a Window like:
OutputWindow("functionname: bla bla bla %d");
The functionname should be replaced by the function that called OutputWindow()
OutputWindow("%s: bla bla bla %d", __FOONAME__);
Thanks for any help!
|
|
|
|
|
AdAkta wrote: But how do I get the name of the function I'm just in?
I'm using VisualStudio 6.0, programming in pure C.
No way that I'm familar with. See here for another possibility.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Thanks for your hint! I will try xtrace.
|
|
|
|
|
You can use __FUNCTION__ as per the following from MSDN[^]
__FUNCTION__ Valid only within a function and returns the undecorated name of the enclosing function (as a string). __FUNCTION__ is not expanded if you use the /EP or /P compiler option.
The only down side is that it's Microsoft specific
In my own code I put a first line into each fuction like this
CONTEXT( _TXT( "CCoolClass::FantasticFunction" ) );
The CONTEXT Macro vanishes in Release builds but in Debug builds it expands into a FunctionContext object which goes on the stack and has all sorts of useful functions. The current FunctionContext object is tracked so I can do my own custom stack traces at runtime limited to my code of course, detect stack corruption, maintain a trace-level variable that records how deep down the funtion stack I am and allows easier formatting of runtime debug output, retrieve the function name anywhere I need it and it even has a special registry within it so I can hook temporary heap allocations to it and unwind them automatically if an exception is thrown that would cause them to leak So much good stuff for adding one line of code to each function is not to be missed.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
Sounds great! Have you published your macro here?
The __FUNCTION__ or __func__ intrinsics do not work with VC++ 6.0 - as far as I know! Only with other compilers like GCC
|
|
|
|
|
AdAkta wrote: The __FUNCTION__ or __func__ intrinsics do not work with VC++ 6.0
That's a pity. I hope you have found a successful solution elsewhere.
I haven't published my Function Context Macro on CP yet but I hope to eventually. I'm working on a Patterns related article and after that hopefully a comprehensive Error/Exception handling scheme which will definitely include Function Context.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
What is the correct way to do this, I have a dialog and when I hit enter after editing a number in an edit box, it's acting like another button is being pressed even though that's not active by tab order or whatever.
I'm sure I remember seeing a way that you could trap the Enter key so it doesn't do anything unexpected
t.i.a
Lee
|
|
|
|
|
See if this helps.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
thanks, I have OnOk and OnCancel managed manually, and my program correctly exits via the red X button on the title bar, and through File->Exit
my problem is not that the dialog is closing but that pressing the Enter key while in an edit control is somehow activating a press of another button thats adding that data to a listview elsewhere. Since the user is typing into the edit control, I assumed the focus was there, so don't understand how that is turning into the same action as pressing this other button (that is not at the top of the tab order tree, so it's not like it's defaulting to that)
|
|
|
|
|
Does the edit control have the ES_WANTRETURN style?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I've tried it with (by setting the "want return" style in the visual dialog editor) and without (which is was before). same result!
|
|
|
|
|
Fair enough. Without walking through the code myself, I've no more suggestions.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
OK, removing the "default button" style now works, but NOW it closes the dialog, even though I have overridden the OnOk and OnCancel functions.
|
|
|
|
|
which is fine, I've now stopped OnOk from closing the diagram
thanks chaps!
|
|
|
|
|
When you press enter the framework calls the default action for OK (just like pressing the IDOK button).
So you either have to override OnOk method or set that edit box to "Want Return"(which you can do from the Properties window)
|
|
|
|
|
no, it's not exiting, it's acting like a button is being pressed. the edit control is Tab oRder 5, contains a number, there is another numeric edit at tab order 6, then tab order 7 is a button which adds some calculated data to a listview report. hitting enter after the data in edit box 5 is causing the data to be added to the table.
Is there any way I can track what's causing this?
|
|
|
|
|
Do you process VK_RETURN (not sure that's the way it's spelled) anywhere? Can you post the code?
Anyway setting WM_RETURN style should leave focus to that editbox unless the Enter key is handled somewhere else
|
|
|
|
|
I'm using Acrobat Activex in a dialog and i want to set printing options to 3 copies each time the user presses the "print" button (from the activex). Can i do this without adding my own print button?
|
|
|
|
|
Is Visual C++ 6 compatible with Vista?
|
|
|
|
|
Daniel Kanev wrote: Is Visual C++ 6 compatible with Vista?
Yes.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
try, you'll see...
|
|
|
|
|
Yes, even though Vista will say otherwise, VC6 works fine.
|
|
|
|
|
Hello!!
I m having a problem with waiting for a single object. My app freezes when the wait-function kicks in.
This happens inside a dlg... maybe that is the reason why it freezes??? (because I want to keep track of the update steps -> reading values, downloading CAB-file and installing)
Here s my code:
if (CreateProcess(lpAppPath, // wceload.exe
strCommandLine, // \somepath\test.CAB /delete 1
NULL,
NULL,
FALSE,
0,
NULL,
NULL,
&startupInfo,
&processInformation
)
)
{
WaitForSingleObject(processInformation.hProcess, INFINITE);//here is where the program freezes
CloseHandle(processInformation.hProcess);
CloseHandle(processInformation.hThread);
}
Please can anybody help me!!!
-erik
-- modified at 11:24 Friday 6th July, 2007
|
|
|
|
|
it waits for the program started thru CreateProcess() ends...
did you ensure that it actually terminated ?
|
|
|
|
|
What i want to do, is install the CAB-file. The cabfile gets installed, but the waitforsingleobject does not understand that the install is finished. Maybe that is because wceload has not terminated yet? if so, is there a way to end wceload on install completion?
|
|
|
|