|
there is MSCOMMON COMPONENT
by the way are you Chinese?
If you are Chinese ,Please communicate with me
my email is jerry_yu_fishery@hotmail.com
I
|
|
|
|
|
I just wanted to know whether it is possible to have some of the items in a Combo Box disabled/grayed/non-selectable.
If yes, how? I didn't find any clue in MSDN.
It's better to know some of the questions than all of the answers.
Pravin.
|
|
|
|
|
Simple answer: Impossible.
An owner-drawn combobox would help here, but I advise against it: It violates every UI design guideline. A better way would be to manage your content - delete invalid combobox items.
----------------------
~hamster1
|
|
|
|
|
char t1[12] ="Codeproject";
char t2[3];
strcpy(t2,t1);
AfxMessageBox(t2)
what'll be the output??
thanx
V
|
|
|
|
|
Why not just try to build and run it?
Most likely, the output will be "Codeproject", but you've hosed something.
Bob Ciora
|
|
|
|
|
it won't work as you are trying to cat a 12 characters long string into a 3 characters long array...
[edit]
there will be an "out of range exception"...
According to the MSDN[^], "Because strcpy does not check for sufficient space in strDestination before copying strSource, it is a potential cause of buffer overruns."
[/edit]
TOXCCT >>> GEII power [toxcct][VisualCalc]
-- modified at 7:34 Monday 29th August, 2005
|
|
|
|
|
this is not happening .. its displayin "codeproject" then what's the use of declaring it as the var t2 as [3] ? i dont understand!
V
|
|
|
|
|
if you can see it, it is pure luck !
it is because - as it's been asnwsered to me here - there is some empty room after the char[3] variable, but never you should think there will always be...
moreover, what do you think about releasing the memory ?
TOXCCT >>> GEII power [toxcct][VisualCalc]
-- modified at 7:26 Monday 29th August, 2005
|
|
|
|
|
u know buffer overflow error when u declare it as t2[3]="Codeproject".... releasing ? what will it do here?
V
|
|
|
|
|
i think it's a good point to wonder how things work, but there's no reason to do so when you perfectly know it is a bad thing to do...
doing t2[3]="Codeproject", it will free t2, but t2 don't have "Codeproject" in it... (the constructor thrown the exception while trying to assigning the string...)
(ps: you can delete your other postwritten twice)
TOXCCT >>> GEII power [toxcct][VisualCalc]
-- modified at 7:44 Monday 29th August, 2005
|
|
|
|
|
u know i get "buffer overflow error" when u declare it as t2[3]="Codeproject".... BTW releasing ? what will it do here?
V
|
|
|
|
|
|
|
toxxct
but i got output Codeproject
|
|
|
|
|
Probably :p Depends on what's after the output string. If there is more room in the data space, then some poor unsuspecting variable will be stomped. But you won't see that until you need it.
Bob Ciora
|
|
|
|
|
TOX,
i too got "CodeProject".. y no error is displayed?
V
-- modified at 7:32 Monday 29th August, 2005
|
|
|
|
|
yes, i understood that point. did you visit the link to the msdn i provided ?
strcpy() doesn't check for sufficient space in strDestination before copying strSource...
TOXCCT >>> GEII power [toxcct][VisualCalc]
-- modified at 7:34 Monday 29th August, 2005
|
|
|
|
|
|
char *strcpy( char *strDestination, const char *strSource );
The strcpy function copies strSource, including the terminating null character, to the location specified by strDestination. No overflow checking is performed when strings are copied or appended.
Have a look at the strlen() function.
Regards
We can do no great things, only small things with great love. - Mother Theresa
|
|
|
|
|
To complete the previous answers:
It will perhaps output 'Codeproject' but you cannot be sure because strcpy is copying the charcters outside the bounds of t2 (so in 'unprotected memory'). So, this memory is not 'locked' and your program can write other things in it. Even worse, because you are writing outside the bounds of t2, it may be that you write on some memory allocated for another variable, thus, erasing it's value that can lead to really baaaaaad things (like your variable changed magically)
|
|
|
|
|
cedric moonen wrote:
Even worse, because you are writing outside the bounds of t2, it may be that you write on some memory allocated for another variable, thus, erasing it's value
cedric,
if the other variable is declared ,as u said it could reside only in 'protected memory' then how will it(unsure strcpy!) overwrite on a content which is in protected memory?.. plz expln
Thanx
V
-- modified at 7:46 Monday 29th August, 2005
|
|
|
|
|
Sorry, protected was not really the good word. What I meant is memory allocated for another variable. strcpy will never check 1) that it writes still in the bounds of the string 2) if the memory it writes to is already allocated or not.
When you declare a variable, memory is allocated for it to holds its value. So if something write at this location in memory, the value of the variable will altered.
|
|
|
|
|
so by no way u can assure that a properly declared variable can never get its value corrupted? so sad.. .. anyway.. thank you so much
V
|
|
|
|
|
t1 and t2 are stack variables. Your allocation makes the compiler to reserve memory on the stack for t1 and t2.
The order of the allocation is undefined (I think).
So if you are lucky, it the stack allocation starts with t2, followed by t1. You copy the content of t1 to t2, including the terminating \0, and nothing happens. Output will be "Codeproject". (If you output t1, it will be "eproject").
If it´s allocated the other way around, it will still output "Codeproject", but your program will likely go bananas when the function terminates, due to the corrupted stack. (The stack also contains the address to return to, usually the address to the function that called the present function).
There are a lot of articles about what´s on the stack, written by people with far more knowledge on the subject than myself. If you want accurate info, pls. read those articles.
|
|
|
|
|
Depends on what you do after the code provided ... all after the third character can be overwritten at any time so, this data, is unsecured.
... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.
|
|
|
|