|
Following MSDN's instructions, I put the ON_BN_CLICKED() macro in the message map , like this:
ON_BN_CLICKED (IDC_MYBUTTON, OnClicked)
where IDC_MYBUTTON is the ID I give to the button when I create it, and OnClicked is the message handler I defined for the event, in the same file as the message map.
I tried to put this kind of event management everywhere in the project, but it never worked .
When you say "disabled" , what do you mean ? to be disabled,a push button must be created that way, right ?
Anyway if it were disabled, it wouldn't send the WM_LBUTTONDOWN message I guess, right ?
modified on Wednesday, July 27, 2011 6:03 AM
|
|
|
|
|
I want to compile cpp files using unicode charset and functions( like lstrlenW ) in console window. But I don't know the option to turn on the UNICODE.
could someone help me?
cl.exe \U ???
|
|
|
|
|
/D "_UNICODE" /D "UNICODE"
|
|
|
|
|
Hi,
I just found that the keyword Delete doesn't mean ^delete^ the way we(or maybe just I) normally think it does.
I thought if you delete a reference, the reference is deleted right after the delete and to have NULL value, which is not so true.
Let me show you an example.
--------------------------------------------
#include <iostream>
class test
{
public:
char ch;
~test() { printf("End!\n"); }
};
class test2
{
public:
char ch2;
~test2() { printf("End!\n"); }
};
int main()
{
test* callFunc = new test();
callFunc ->ch = 'a';
delete callFunc;
test2* callFunc2 = new test2();
printf("%p %p\n",(void*)callFunc,(void*)callFunc2);
callFunc2 -> ch2 = 'b';
printf("%c %c \n",callFunc ->ch ,callFunc2 -> ch2);
}
End!
0395BA8 0395BA8
b b
--------------------------------------------
From this result, I want to theorize that the keyword Delete is just to let the references that you delete be available to be pasted later.
I'd like to know if my idea is correct or if there are some other reasons for this?
Thanks in advance.
|
|
|
|
|
This is one of the anomalies of delete in C++. When an object (or block of memory) is deleted then it is marked as free and may be re-used at some later time. However, the actual memory content, and any pointers to it, will not be physically cleared. If you had followed your delete statement with some other statement that needed to allocate memory, then it is likely that the program would have failed, as callFunc would (probably) be pointing at something that was not a test object.
When deleting objects you should always reset any pointers to NULL in order to protect yourself from any potential hazards.
The best things in life are not things.
|
|
|
|
|
Thanks. This helps me a lot.
|
|
|
|
|
Dean Seo wrote: if there are some other reasons for this?
a pointer to a block of allocated memory is not set to NULL when you delete that block of memory. you need to pay attention to that fact when deleting memory.
also, in C++ a pointer is not a reference.
int foo(int &a, int *b)
{
...
}
a is a reference. b is a pointer.
|
|
|
|
|
|
Besides the above comments you might want to read up on what a 'heap' represents in computer science both conceptually and via implementations.
|
|
|
|
|
|
new does three things:
1. allocate memory from the heap
2. initialize the object at the resulting memory location
3. return a pointer to this new object.
What it does not do is set the value of your pointer variable - this is done by the assignment operator '='.
delete does the reverse, in reverse order:
1. take a pointer to an existing object
2. destruct the object
3. deallocate the memory it occupied
What it does not is reset the value of your pointer variable.
Technically it wouldn't be so hard to make delete also reset your pointer variable to 0, but since 'cleaning up' is often done at the end of a function or the end of the scope a pointer is defined in, it is usually not neccessary.
Nevertheless it is a good idea to always explicitely set a pointer to 0 after calling delete on it! Even if your delete is the very last line in your code, someone might later add code to that function, past that line.
That said, it might have been better if the C++ standard required the delete operator to also set the pointer to 0. But it doesn't. Of course, it is possible to overwrite delete , if you really want it that way...
|
|
|
|
|
Technically you are describing the "new expression" and "delete expression".
Not be confused for example with the new operator and delete operator.
|
|
|
|
|
Hi all,
now i want to work with XML file in my dialog based application,please help me to create a xml file that contains some details about application and please help me how to read and update this xml file in my application.
i have no idea about XML file.
if possible please provide me any sample or example fot this.
i am waiting for ur valuable suggestions.
please help me for this.
thanks in advance.
|
|
|
|
|
|
there is any working example for this coz use of tinyxml.h generates so many errors.
|
|
|
|
|
There is a working sample on the page that Rajesh pointed you at. If you are getting errors then show the code and the error messages and people will try to help you resolve them.
The best things in life are not things.
|
|
|
|
|
Le@rner wrote: please help me how to read...xml file in my application.
Here is another example.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
thanks its a very gud article.
|
|
|
|
|
|
My c++ test version is 6.74, seems it doesn't support VS2008.Is it possible to set something like "compiler" to make it support VS2008?
|
|
|
|
|
You should rather check Parasoft's[^] site and maybe ask there. If you click the "Supported Environments" tab-thingie on the site it seems to list VS2008.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> //TODO: Implement signature here<
|
|
|
|
|
template< size_t N >
void cdecl _DumpWin32StructFields( WCHAR (&szBuffer)[N], LPCWSTR pszFormat, ... )
{
va_list pFirstParam ;
va_start( pFirstParam, pszFormat ) ;
StringCchVPrintf( szBuffer, N,pszFormat, pFirstParam ) ;
va_end( pFirstParam ) ;
}
If I put the function definition in a different obj file than the caller, it fails to link reporting I didn't give definition to _DumpWin32StructFields, actually I do,in another obj, it's just too stupid for the linker to find out.
Is there a solution if I don't put caller and the function together?
|
|
|
|
|
A template class or template function is resolved during compile time.
Symbols in an OBJ file are resolved during link time.
So to use templates, you have to provide template source access to the calling file.
The problem you're facing is not because the linker is stupid.
It's because it's the compiler that resolves templates and not the linker.
|
|
|
|
|
Thanks, I think you are right. I searched some materials, says the compiler won't embed the template definition( blueprint ) into an obj until it is called. So I simply put it in a common header file, but I am still worried if more than one cpp call the template with the same function prototype.
|
|
|
|
|
If you want to use a function from different cpp files you have to make the declaration (the function signature) available to both. In the case of a template function, the same goes for its definition! To avoid code duplication, the right place to put this is a header file, not a cpp file.
template< size_t N >
void cdecl _DumpWin32StructFields( WCHAR (&szBuffer)[N], LPCWSTR pszFormat, ... )
{
va_list pFirstParam ;
va_start( pFirstParam, pszFormat ) ;
StringCchVPrintf( szBuffer, N,pszFormat, pFirstParam ) ;
va_end( pFirstParam ) ;
}
#include "dump.hpp"
void foo() {
WCHAR buffer[20];
_DumpWin32StructFields(buffer, _T("Hello World!"));
}
#include "dump.hpp"
void bar() {
WCHAR buffer[30];
_DunpWin32StructFields(buffer, _T("Goodbye Cruel World!"));
}
This will force the compiler to instantiate and create code for your template function for both foo.obj and bar.obj, and the linker won't have trouble finding them.
|
|
|
|