|
But when I search for it, the only two instances of 'define new' are the standard one below in my dialog and app .cpp files. Could it be defined some other way? Or any other workaround to make it compilable in debug mode?
Thanks.
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
|
|
|
|
|
Do you really need to call the operator directly?
Can you just use the vector form of new and allocate an array of bytes?
return new BYTE[size];
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Well, the thing is that the call is made from the class I downloaded from CP (see my first post above). If I change the object, then I have to modify the class as well, right?
What makes me wonder is that how come I can run the demo code in debug mode and step thru line-by-line, while in my test project I can't even compile the debug mode? They both using the same classes!
Any ideas? thanks for any suggestion.
|
|
|
|
|
If the problem is with using the DEBUG_NEW operator in debug builds, then you
can wrap your calls to operator new with something like
#pragma push_macro("new")
#undef new
...
(use the new operator here)
...
#pragma pop_macro("new")
The problem is, where do you put this in a template class? Do you put it in the class
declaration or do you have to remember to do it every place you instantiate an object
of the class?
I haven't seen the rest of the class in question, but I assume if it calls operator new, then
it must call operator delete somewhere. Those should be the only calls you'd need to change.
I have no idea why the author did that - is the operator new overloaded in the class?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: #pragma push_macro("new")
#undef new
...
(use the new operator here)
...
#pragma pop_macro("new")
That's cool. I didn't know about the #pragma push_macro . Thanks for mentioning it.
Nathan
|
|
|
|
|
You are right about the conflict is with the definition of DEBUG_NEW operator in debug builds. As soon as I commented all instances, it compiled fine.
I can't find any code that overload new operator in the class, though...
Using the push_macro and pop_macro resulted this error:
#pragma push_macro : 'new' is not currently defined as a macro
Anyway, what's the effect I will get by commenting out the definition of DEBUG_NEW? Thanks.
|
|
|
|
|
Joe Smith IX wrote: what's the effect I will get by commenting out the definition of DEBUG_NEW?
You just lose the file/linenumber info in debug builds that aid in finding memory leaks.
I'm still not sure why the author used new like that...
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
In that case, is there any way to undef the DEBUG_NEW just before the conflicting code, and then re-define it right afterward?
Something like below: (except this one generated one warning)
static void* Alloc(UINT size)
{
#ifdef _DEBUG
#undef new DEBUG_NEW // <-- compile warning C4067: unexpected tokens following preprocessor directive - expected a newline
#endif
return operator new(size);
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
} Thanks.
|
|
|
|
|
Sorry for the late reply - did you get this working?
The line with the warning should be just
#undef new As I mentioned before, I'm just not sure where this should be in a template class.
Since the actual class is built where an object is instantiated, I'm not sure if
the #undef stuff needs to be there or if it worke by putting it in the template declaration.
If it works in the template declaration (as you've shown) then that's cool
It's easy enough to test.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
|
hey all!
i am an amateur in VC++! i ve got a problem and that is by pressing Enter Key of keyboard, my program shuts down as i guess its by default!
Now my program uses a text box and what i want is is when i write something and press Enter! the Enter key activate an Event Handler! or a specified function say displaying the text what is written in the text box in other list box etc!
plzz anyone who can help in this regard!
also is there any way to creat my own event handler????
Like for Enter key? as there is one for helpinfo with WM_HELPINFO which activates if F1 is pressed!
I ll be grateful if anyone lead me to the solution!
whats wrong wit'cha?
|
|
|
|
|
In a Dialog box the enter key causes the OnOK method to get called.
There are a couple of ways you can do this, you can do your processing in OnOK but not call CDialog::OnOK, and to make the OK button work again, you will need to add an event handler for the ok button and in there call CDialog::OnOK.
Or you can catch the WM_KEYDOWN message for the VK_ENTER key in PreTranslateMessage and do your processing there, but don't call CDialog::PreTranslateMessage when the enter key is pressed.
AliR.
Visual C++ MVP
|
|
|
|
|
well i didn get ya !
wat i wanna do is to use tht Enter key for activating any of my desired button! Like say a button Send! if i write something in the text box and press Enter! it works if i ve CLICKED Send!
i ll be grateful if u clearify it a bit!
|
|
|
|
|
ddspliting wrote: I ll be grateful if anyone lead me to the solution!
See here and here.
"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
|
|
|
|
|
well thnxx david! but see this!
switch (nChar)
{
case VK_RETURN: OnBsend();
}
so if VK_RETURN is the case then call OnBsend() function!
am i right? but if now i press Enter ! then still the program closes!!?
please reflect light on tht
|
|
|
|
|
What is happening in the OnOK() handler()?
"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
|
|
|
|
|
well i havent used OnOK() Handler! and truelly speakin i dunno well abt tht! i do know tht Enter key initiate the OnOK() handler and so the program closes! but how to remove this property from enter key?
u know clicking Send Button while working in a TextBox is cumbersome! just like chat in msn messenger or yahoo ones window! where when we press Enter! or wat u call RETURN the message is sent or we can say tht Send button is activated!
|
|
|
|
|
ddspliting wrote: well i havent used OnOK() Handler! and truelly speakin i dunno well abt tht! i do know tht Enter key initiate the OnOK() handler and so the program closes! but how to remove this property from enter key?
So did you bother to read this?
"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
|
|
|
|
|
Read? What programmers read? Pfffffffft we "write" .... code. We don't need no stinkin readin
|
|
|
|
|
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Sorry!
I read tht a bit late! and my problem is solved now! thanxx to u David and to the codeproject! Really Nice Service! top that!
|
|
|
|
|
I have a CSpinButtonCtrl in a dialog box and want to check changes to its value only after the user releases the mouse button. It seems that the spin control sends WM_VSCROLL messages with SB_THUMBPOSITION set even before the user releases the mouse button. Can anyone tell me how to process only the final message, and not all the ones in between (I don't think WM_LBUTTONUP would do it, since I need to determine which control it came from, and that message doesn't seem to tell me that.)
Thanks!
|
|
|
|
|
Californian2 wrote: ...(I don't think WM_LBUTTONUP would do it, since I need to determine which control it came from, and that message doesn't seem to tell me that.)
How are you verifying this?
"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 have an OnVScroll handler in my dialog box procedure which checks whether nSBCode equals SB_THUMBPOSITION, and the part of the code that should only run if SB_THUMBPOSITION is set is being run before the mouse button is released.
|
|
|
|
|
Californian2 wrote: I have an OnVScroll handler in my dialog box procedure...
And the third parameter of that override is (a pointer to) the control you are after.
"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
|
|
|
|