|
Anonymous wrote:
So it's max value is 2^32 - 1 = 4,294,967,295. These represent milliseconds. Which means over 4 million seconds, which means over 700,000 minutes, which means over 11,000 hours, which means over an year...
Close. It is actually over 4 billion seconds, which is roughly 49.7 years. Last I remember, anything over 65,536 would not work. I just tried it with 90,000 and it worked as expected. Go figure!
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
|
Another solution is a timer queue timer.
Kuphryn
|
|
|
|
|
Another solution is a timer queue timer.
Could you please explain what you mean here. Thnx
"...Ability to type is not enough to become a Programmer. Unless you type in VB. But then again you have to type really fast..."
Me
|
|
|
|
|
Check out CreateTimerQueue() and CreateTimerQueueTimer() . The timers are lightweight objects that enable you to specify a callback function to be called when the specified due time arrives.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
That's helpfull: supported only on 2000 and up...
Thnx
"...Ability to type is not enough to become a Programmer. Unless you type in VB. But then again you have to type really fast..."
Me
|
|
|
|
|
You can also use GetTickCount()
DWORD dwBeginOf5Secs = GetTickCount();
while (TRUE)
{
if (GetTickCount() - dwBeginOf5Secs > 5000)
{
dwBeginOf5Secs = GetTickCount();
}
else
Sleep(100);
}
Peter Molnar
|
|
|
|
|
I am reading in CString values from a file and atoi-ing them. Docs say it returns 0 if the string cant be converted to a number (though the example there says atoi("5 cars") returns 5 -- I thought it would return 0 ???) Confused about this.
The other thing is that I might have a CString "0". If atoi returns 0 in this case, then its not signalling an error. So would I treat the case of strings like "0" separately?
Thanks,
ns
|
|
|
|
|
atoi() would return 0 for "cars 5" since it found no numbers before it found a non-number. In other words, it converts all numbers up to the first non-number encountered.
Differentiating between the return values of atoi("0") and atoi("T") sounds like a design issue. What is the format of the incoming data?
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
The data has been writeString--ed to a file with a %d format.
So I read it back in later and want to make sure someone didnt inadvertently change what should be a numerical entry in the input file, into a alphabetical entry.....so I was going to use atoi to check the readstring-ed CString......
Thanks,
ns
|
|
|
|
|
So your file should look like:
123
456
004
991
...
and you want to ensure that someone hasn't changed it to:
07b
1c8
004
3df
...
Is that an accurate assesment? If so, you'll need to employ ReadString() to read each line from the file and parse the data yourself, something like:
CString strLine;
while (...)
{
file.ReadString(strLine);
if (! IsAllNumbers(strLine))
AfxMessageBox(...);
}
bool IsAllNumbers( LPCSTR lpszData )
{
while ('\0' != *lpszData)
{
if (isdigit(*lpszData))
lpszData++;
else
return false;
}
return true;
}
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Thank you so much! Its exactly what the scenario is and your resolution works really well! I appreciate having this snippet of code to "import" into my project.
ns
|
|
|
|
|
atoi starts translation first by removing seperator characters(like space) from the string, looking for the first character. if it is a digit, it starts translating it into an integer, but if not, it returns zero.
you can use it like this:
LPSTR ss="4 cars";
int x=atoi(ss);
if(x==0 && strcmp(ss,"0")){
// the input is probably not a real zero,
// it's an error
}
|
|
|
|
|
Actually it would be better to use strncmp instead of strcmp because then you specify the number of characters to compare so it would return correctly if the string contained "0 cars" also you would want to trim out the spaces in the string first before the compare in case you had a string " 0 cars" so that it would return correctly as well.
|
|
|
|
|
Appreciate the explanation and the nifty way to handle it.
Many thanks,
ns
|
|
|
|
|
I usually use isdigit() to test for such things.
Calling a function that carries out an operation that you have no intent on using just to see if it returns an error isn't typically considered good design.
|
|
|
|
|
For example:
'D:\Documents and Settings\Grrrr\My Documents'
In VC++6.0, which function or API or Class can do this?
Thanks a lot...
|
|
|
|
|
use SHGetSpecialFolderPath
|
|
|
|
|
This method is the simplest method??
Just now, I have read this function in MSDN.
I found it use Shell...
I thought there have a simple mothod, I thought we can get the path-name
direct, use a API. as 'GetSystemDirectory'.
I'm sorry.perhaps i am wrong.
|
|
|
|
|
|
HEY LOOK I THE FAQ SECTION I SAW THIS THERE GOOD LUCK
H43K4Z
|
|
|
|
|
I'm still a green horn in the area of COM and I have some business object classes I want to put in a com server(either DLL or EXE).How do I achieve this using wizards and Compiler COM support(attributes etc.)?
I've been using MFC for some time now.
What would life be without politicians and programmers?
|
|
|
|
|
I think that your topic might be beyond the scope of the forums, but a good place to start is "Beginning ATL 3 COM" ISBN: 1861001207 and "Professional ATL COM Programming" ISBN: 1861001401 if you can still find them. They are a great start and cover using COM and developing COM objects in C++.
|
|
|
|
|
Hi, I've created a server using dialog which listens to any incoming client connections. here, while the server listens, it is blocked in an infinite loop while accepting connections. Now I want the server to create a new thread for every connection with a new client. how can I do this.
Also, I cannot write the thread handler as a member function of a class. how can i do that?
Shenthil
|
|
|
|
|
Shenthil wrote:
Now I want the server to create a new thread for every connection with a new client.
Really? Are you sure you want that many potential threads/connections? Have you considered a thread pool?
Shenthil wrote:
Also, I cannot write the thread handler as a member function of a class. how can i do that?
Use a static member.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|