-
May 30th, 2012, 08:36 PM
#1
vc6 to 2008 null character
Hello,
I am migrating a bit of code from vc6 to 2008 and have came across a bit of code that I have put an example of below. My question is, in the case of value1 becoming 0 from the comboBox, why would this have not returned NULL in vc6?
Code:
CString exampleString;
unsigned long value1;
char* value2 = (char*) &value1;
char* buf;
value1 = exampleCombo.GetSelData();
buf = exampleString.GetBufferSetLength(1);
buffer[0] = (value2[0]);
exampleString.ReleaseBuffer(1);
return exampleString;
-
May 30th, 2012, 10:01 PM
#2
Re: vc6 to 2008 null character
Originally Posted by slihm
Hello,
I am migrating a bit of code from vc6 to 2008 and have came across a bit of code that I have put an example of below. My question is, in the case of value1 becoming 0 from the comboBox, why would this have not returned NULL in vc6?
Why would it?
It returns a string with one character (zero) in it, regardless of he VC version.
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
May 31st, 2012, 01:20 AM
#3
Re: vc6 to 2008 null character
Originally Posted by slihm
Code:
CString exampleString;
unsigned long value1;
char* value2 = (char*) &value1;
char* buf;
value1 = exampleCombo.GetSelData();
buf = exampleString.GetBufferSetLength(1);
buffer[0] = (value2[0]);
exampleString.ReleaseBuffer(1);
return exampleString;
What does this casting mean?
Code:
unsigned long value1;
char* value2 = (char*) &value1;
char* buf;
And what for?
What is buffer?
What is GetSelData()?
Victor Nijegorodov
-
May 31st, 2012, 04:04 AM
#4
Re: vc6 to 2008 null character
Originally Posted by slihm
Hello,
I am migrating a bit of code from vc6 to 2008 and have came across a bit of code that I have put an example of below.
Explain what that code is supposed to accomplish. Whatever it is, I can bet there are a lot more safer ways to do this than casting all over the place like that.
If you removed all of those casts, does the compiler give you errors? If so, then what you're doing is dangerous, and possibly you were only lucky this "works" in Visual C++ 6.0. Usage of C-style casts to "shut the compiler up" usually means that whatever you're doing, don't do it.
Also, a CString in later versions of the Visual C++ compiler (later than 6.0) compiler is based on TCHAR, not char. Therefore if the character set you chose when creating the project is Unicode, this code will either not compile, or it will not work properly.
Get rid of the casts, observe the errors (if any) that the compiler gives you, and rethink what is being done. Again, please state on a high level what that code is supposed to do.
Regards,
Paul McKenzie
-
May 31st, 2012, 06:22 PM
#5
Re: vc6 to 2008 null character
Thank you for your responses. I am not the original author so I am trying to understand the logic myself. There are no compile issues. From my debugging I have found the purpose of the casting and buffer to be to create a symbol character from the returned value of GetSelData (a combo box that returns 0 if the first item is selected, 1 if the second is selected etc.) and return the symbol character back as a CString to the calling function. For example, if 1 is returned from GetSelData the symbol returned is a space (" "), if 5 is returned from GetSelData the symbol becomes a U ("U") that is returned in the CString. However, the calling function does not behave properly when NULL is returned which is returned when GetSelData is 0 because it expects a symbol character of some kind. What could this bit of code have returned other than NULL when the combo box was 0?
-
May 31st, 2012, 07:22 PM
#6
Re: vc6 to 2008 null character
The code you've shown doesn't make any sense at all. VictorN asked the obvious questions, so there really isn't much anybody can do with what you've given.
Also, your function returns a CString. It can't return NULL.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|