Sorry, but it is not safe: sure, the pointer still 'points' at the same address but the contents of the strings are not protected anymore
Since his function was returning a string literal, it is safe. String literals are stored in static memory, so the pointer he returns will be pointing to a location in memory that will ALWAYS have that string (at least as long as that program is running).
Granted, this is not a desirable way to return such data, but it is both legal and safe.
Cedric Moonen wrote:
So, later in your program you may find garbage characters in your string and you don't know way. It is like using a string allocated with new after having deleted it.
That would have been the case if the code he wrote was changed to:
Odd - I have no idea why your post was voted down, it was completely correct.
-=- JamesIf you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
I am newbie in VC++. I was facing the problem while executing application(.exe) build using VC8. The application was ported from VC6 to VC8. The problem I was the error:
MSVCR80.dll was not found. Re-installing the app........
I gone through many articles and found this is a rather common problem. I checked my application manifest file which was correct and refering to new MFC 8. Also checked .exe which has manifest file embeded under RT_Manifest with id 1. So nothing seems to be wrong still i was not able to run .exe. When I checked with DEPENDACY WALKER it was showing same error that he couldnt found msvcr80.dll.
After that I changed setting for linker to ignore library MSVCRT.LIb. And now the problem is no more. When I checked .EXE with Dependency Walker, I was getting MSCVR80D.dll for debug build. Also my application is able to run now.
Is it right thing whatever I have done?? Is ignoring library MSVCRT.LIb is a right option. I hope it wont create problems in future.
Try running your application in a system which does not have Visual Studio installed. (If needed the system may have .NET framework though.) If it runs well once, it will run again anywhere, provided you also distribute the dependent DLLs with your application.
That means My application wont link to default MSVCRT.lib(VER:6 for VC6). And thats why its linking to new Ver:8 according to manifest file.
But again that leaves the question that why are those policies needed in WinSxS folder. Those policies are clearly indicating that any reference to old ver should redirect to the New version.
Seems some problem with policies!
Ok, I think I should answer your question in detail.
Now, when you said you are migrating a project from VC6 to VC8, I am assuming that you have just opened the existing VC6 project file in VC8. So the linker directories were retained in the new project which was opened in VC8. This will happen if the programmer who had originally created the project had explicitly linked to MSVCRT.LIB (which is actually the c-runtime library). So the VC8 compiler was trying to link to that LIB as well! And since .lib files are not compiler independent, you got an error. I am not sure if you unlinked the older version 6 library! Please let me know.
Secondly, if the programmer had not, linked to the MSVCRT.lib explicitly, then the compiler will not look for version 6 of MSVCRT. Instead it will look for the current version i.e. version 8 of MSVCRT.lib. By the way, lining to MSVCRT.lib requires you to distribute MSVCRT80.dll with the application. Take a look at this for further details: http://msdn2.microsoft.com/en-us/library/abx4dbyh.aspx
Since, it was not present in the application directory, the error was found.
However all this is my own conjecture. I suggest it would be better if you post the buildlog.htm (that is generated in the debug folder) here in this forum so I can take a closer look.
I understood what u r trying to say. I checked my project and other dependent projects too. I found that some of my projects were linking to MSVCRT, but besides that its a correct version i.e 8 of MSVCRT is getting loaded. This I checked using DEpendancy Walker.
This is what I done while converting projects from VC6 to VC8. I copied full folders, made back-up and then used new copy. So I think its not the case 1 as u told.
>lining to MSVCRT.lib requires you to distribute MSVCRT80.dll with the application
I am not sure about this one. But I think that is why there is a manifest file. When i gone through some articles I found that manifest files are responsible for getting these dlls. Also manifest files are embeded into the appilcation(.exe). I also checked that and it was found in my .exe.
Althogh my problem has been solved using Debug build. I just want to confirm that my release build also work fine.
I'm a noobie of visual c++ and currently using vc++ express 2005.
I'm creating an application to handle data from a device connected both
on a serial port and via tcp/ip networking and been successful with the work so far.
My problem is within the application interface.
I have a mdichild which will show data send from the device within the serial port and then
do some decoding and throw it as keystokes.
Within the mdichild I put a button which when it clicked it will send the data into another
mdichild form ( which will process the data, querying, bla.. bla..bla...)
How can I acomplish this ?
The file looks like this ESIM 6 PPS01..
The Model name is PPS01..but it reads like tht it neglect first 2 characters in the name and read only "S01" if the model name is DT002 then it reads on ly "002"..
What can i do?
That is false. sizeof(int) returns 4, so you read 4 characters ! You have to make a difference between the size of an integer (always 4 bytes) and the size of the string that represents this character (can vary depending of the number of digits).
If your integer is always smaller than 10, then you can read only one char. But if you don't know how many digits it will contain, then you are in trouble. It is better to store the complete line in a buffer and then scan it for white spaces inside it (like I suggested yesterday). Or use scanf as somebody suggested you also.
hi all i had written text in event viewer and ,for that i had also written in the registry setting related to the services i.e
when i c that in rejistry sampleapp folder is created with its contents,text in the event viewer is aslo written but with the text follwing message also appear.
The description for Event ID ( 1 ) in Source ( NetBlocker ) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. The following information is part of the event:
"08/10/06 10:48:50 Service Stoped",it is actual text above is the message which i want to skip.
what i m doing wrong first i created rej key and then write in event viewer which MSDN told.
You have to create a dll. That dll contains the texts for the different Event ID's you use.
(There are ways to go around the creation of the dll, I think I saw an article about that here at CP a couple of years ago).
Search for "event log" in the articles section at CP. Or have a look here.[^]