|
CodingLover wrote: Actually I dot this from MSDN and it gives only a compile error that, addition ) at the end.
But it's clearly written in MSDN that this will cause unpredictable results. In fact given as a warning to avoid such code!
From MSDN:
The call will fail if the string object itself is offered as a
parameter to Format. For example, the following code:
CString str = "Some Data";
str.Format("%s%d", str, 123);
will cause unpredictable results.
Also note this...
MSDN:
When you pass a character string as an optional argument, you must
cast it explicitly as LPCTSTR.
Nibu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
I agree with you. 95% of the time you can get away with it but then it fails under certain circumstances. Lots o' fun to debug after you've coded it all over the place.
Convenient? yes.
However, it will piss you off when the unpredictable results come a calling.
Your advice to avoid it is good. However, alot of people will get enough positive behavior that they will convince themselves you are crying the "sky is falling".
They will live and learn someday. 
|
|
|
|
|
bob16972 wrote: Your advice to avoid it is good. However, alot of people will get enough positive behavior that they will convince themselves you are crying the "sky is falling".
But it's documented not to do so!
Nibu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
Don't get me wrong, I agree with you.
It just always confused me why people tend to shun good advice. I am always laughed at for being cautious since it tends to yield the same results as being reckless 9 times out of 10. I sometimes question whether I should just join in and throw caution to the wind, but that's just not me so I continue mind the documentation and take the safer road.
|
|
|
|
|
Ok, in such a case what should I do?
I appreciate your help all the time...
CodingLover
|
|
|
|
|
CodingLover wrote: Ok, in such a case what should I do?
CString str;
str.Format("%s%d", _T( "Some Data" ), 123);
Nibu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
Yes, that's right. But why I try this is, avoid CString in my application and do it using standard C++.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
CString::Format() is based on sprintf() which is based on printf().
TCHAR strBuffer[ 255 ];
_stprintf( strBuffer, _T("%s%d"), _T("Some Data: "), 123 );
_sntprintf( strBuffer, 255, _T("%s%d"), _T("Some Data: "), 123 );
|
|
|
|
|
But I don't like to use buffers to this. In some cases I need to use just a byte to store data.
Anyway, thanks for the replay.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
Thanks for the tip, I was using it wrongly too.
I didn't understand the explanation of that warning when I started to use the function as the OP.
Luckily I had no crash so far :P
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
There are multiple ways. One is as follows:
#include "stdafx.h"
#include <string>
#include <iostream>
#include <sstream>
using namespace std;
int main()
{
ostringstream oss;
oss << "Some data" << 123;
string s = oss.str();
cout << s << endl;
return 0;
}
Another solution (which I prefer) is to use Boost[^]'s Format[^] library as in the following example:
#include "stdafx.h"
#include <iostream>
#include <boost/format.hpp>
using namespace std;
using namespace boost;
int main()
{
cout << format("%1% %2%") % "Some Data" % 123 << endl;
return 0;
}
Steve
|
|
|
|
|
Thanks for the infor. I'm really looking into boost.
One of my friend says that using boost easy to handle command line parameters too. May be my next question on that.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
Hey all, was hoping you could help me with a little info here.
There's this application we use that's around 10+ years old, and I'm pretty sure it was written in C++.
There are some data files it uses with an extension of ".md" and a fileheader of "MDB2"
I was wondering if anyone's come across a database or file type like this in the past. My reasoning is, the source for the app has been lost for some time, but that's ok, the app itself runs decent enough, but we'd really like to update the data in these files if possible.
The powers that be are hoping it's a known format, but I've tried just about everything I could think of to access them.
Thanks!
|
|
|
|
|
Does anybody knows why VC6.0 decided to give me this error message everytime I set breakpoint?
I am about to go thru "standard VC6.0 recovery" - delete /debug , *.clw,
*.aps. Hope it works!
Cheers Vaclav
|
|
|
|
|
i typically see that when the breakpoint was set in a module which wasn't built in debug mode (or didn't have debug info)
|
|
|
|
|
I don't think this was my case. I have been compiling and debugging just fine when it just started happening.
Then it went away! I suspect it may have something to do with running a timer because it give me this error when I was setting the breakpoints in OnTimer function / method. It started working again, but I had other problems when keeping the timer running during debugging so I immediately killed it in OnTimer. When I have a break I’ll try to make it happen again.
Thanks for you help.
Vaclav
|
|
|
|
|
Hi,
i have built a treeview with and a listview (like in the win explorer) and both work fine!
But now i wnt to add a grey label "caption" to the tree control with the text "Folder == Ordner"
http://filehosting.at/images/download.php?file=a77fcc05927371dd5003f214a4cde43c
like in the WinExplorer but i can't manage it ;(
Could somebody explain me how to do this?
Many thanx for your help
Best regards
CrocodileBuck
P.S.: When you click the link above it won't work, but when you copy it in your browser it will work fine, i don't know why ! 
|
|
|
|
|
|
What is the difference between messages starting with WM_ and NM_ ?
Why there are two set of messages for the single (right click)event like:
1. WM_RBUTTONUP
2. WM_NOTIFY NM_RCLICK
Are they completely different?
Regards,
Suman
--
"Programming is an art that fights back!"
|
|
|
|
|
NM is for Notification Messages sent from Window controls to their parent window, where as WM are Windows Messages.
|
|
|
|
|
Dan wrote: NM is for Notification Messages sent from Window controls to their parent window, where as WM are Windows Messages.
thats the classic difference
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You/xml>
|
|
|
|
|
Does anyone have any good ideas how to identifiy which CD is in the drive?
I'd like to do this without reading too much of the drive, i.e. should be fast!
I am using GetVolumeInformation to identify drives. Drives usually have a serial numbers, but many CD's do not.
When the CD or other volume is online, I'd like to gather identifying information about the device -- something unique -- like a serial number.
And later, would like to check if the device at that drive is the same one as I identified before.
This way I can tell whether the volume I thought was there -- is still there.
Any clues for me on how to proceed?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<a href="http://www.soonr.com">SoonR Inc -- PC Power delivered to your phone</a>
|
|
|
|
|
You can try computing HD5 hash of 4-5 files in the CD and also store their path. Then everytime a CD is inserted you check if files you checked last time are present on CD and if their MD5 hases are identical. You may also compute a single unique number by combining file names and file data information. So that comparison is easy.
-Saurabh
|
|
|
|
|
Sample code would be great, thanks very much.
|
|
|
|
|
You don't do anything special.
You expose method with parameters like you would for any ActiveX COM interface.
The user will usually have a script section in the html that instantiates your control, calls the methods, and passes in whatever parameters needed.
Now there is the issue of whether your ActiveX control is "safe for scripting" since you are subject to browser security etc...
|
|
|
|