|
Use COleDateTime or CTime class.
|
|
|
|
|
Depends on the object used to represent times. If using FILETIME use the function you mention above. If using time_t , you can just use greater-than and less-than.
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If 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! See DeleteFXPFiles
|
|
|
|
|
Is reading/writing a 32-bit integer on Win32 guaranteed to be atomic ? I could not find that information anywhere.
wbr Brainley
|
|
|
|
|
|
No. See here[^] for information on how to do it safely. If your programming x86 machine code you could also look up the lock prefix[^].
Steve
|
|
|
|
|
I'm writing a procedure where two values, wich always make up a pair, can be changed from one thread, but read from many. I only want to make shure that a read-operation always returns a valid pair (writing is actually limited by a CRITICAL_SECTION). So i use a checksum. The thread reads the variables and then checks the sum against a checksum. If one of the values got changed somewhere in between, the checksum will not match and it will try again. This works, since simple read/write operations on 32-bit Integers are atomic on 32-bit systems. I chose this way because it is much faster that using a lock mechanism, since write operation happen a lot less often (> factor 20) than write-operations.
|
|
|
|
|
How can it get changed if only one thread ever changes it? How can you be sure it doesn't get
changed while computing the checksum? Is a critical section really that slow?
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
Here a scenarion. Thread A reads, Thread B writes, the pair consists of V1 and V2 of type int.
A reads V1
B writes V1
B writes V2
A reads V2
So now A has a pair that does not belong together. Now consider this :
A reads V1
B writes Checksum V1+V2
B writes V1
B writes V2
A reads V2
A checks the Sum -> does not match, so A tries the read again.
There are a lot more cases, but they all work out.
Using a CRITICAL_SECTION or any other kind of synchronization would mean traps into the OS and context-switches on the wait-operations. In cases where such an optimistic approach is possible, that means the probability of an error, and thus a second or even third read is very low, the performance is higher this way.
|
|
|
|
|
The spin count on a CS object can be utilitized to handle situations like this, but you really need to be on a multi-CPU/multi-core machine to really make use of it.
If the CS is released during the spin count, no context-switch will take place. Given that simple operations are being done, I would bet that you would hit that situation more often than not.
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If 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! See DeleteFXPFiles
|
|
|
|
|
I just hijacked the thread for my own personal learnin'...
Can you explain what the heck you're talking about?
*edit* Google is my friend: Critical Section Objects[^]
Thanks!
Mark
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
Looks like you should do some research on "readers writer locks".
Steve
|
|
|
|
|
hi
i need to read and write the registry values using vc++.
if anyone has any idea please forword itto me.
thanks.
|
|
|
|
|
Have a look at CRegKey on MSDN.
And please delete your previous message.
Glory follows virtue as if it were its shadow.
- Marcus Tullius Cicero
|
|
|
|
|
Here you have some samples...
CRegistry is a class that I use often in order to work with the registry... it's something that we had developed some time ago.
<br />
bool CRegistry::SetKey(HKEY hKey, CString csSubkey, CString csValName, CString csVal)<br />
{<br />
if(hKey != HKEY_CURRENT_USER)<br />
return false;<br />
<br />
if(csSubkey.IsEmpty() || csValName.IsEmpty() || csVal.IsEmpty())<br />
return false;<br />
<br />
HKEY hWkKey;<br />
LONG lRetorn = RegOpenKeyEx(hKey,csSubkey,0,KEY_ALL_ACCESS,&hWkKey);<br />
if(lRetorn == ERROR_SUCCESS)<br />
{<br />
int iLength = csVal.GetLength();<br />
lRetorn = RegSetValueEx(hWkKey,<br />
csValName,<br />
0, <br />
REG_SZ, <br />
(BYTE *)csVal.GetBuffer(0),<br />
iLength);<br />
<br />
RegFlushKey(hWkKey);<br />
RegCloseKey(hWkKey);<br />
<br />
if( lRetorn == ERROR_SUCCESS)<br />
return true;<br />
}<br />
return false;<br />
}<br />
<br />
bool CRegistry::SetKey(HKEY hKey, CString csSubkey, CString csValName, int iVal)<br />
{<br />
if(hKey != HKEY_CURRENT_USER)<br />
return false;<br />
<br />
if(csSubkey.IsEmpty() || csValName.IsEmpty())<br />
return false;<br />
<br />
HKEY hWkKey;<br />
LONG lRetorn = RegOpenKeyEx(hKey,csSubkey,0,KEY_ALL_ACCESS,&hWkKey);<br />
if(lRetorn == ERROR_SUCCESS)<br />
{<br />
int iLength = sizeof(iVal);<br />
lRetorn = RegSetValueEx(hWkKey,<br />
csValName,<br />
0, <br />
REG_DWORD, <br />
(BYTE *)&iVal,<br />
iLength);<br />
<br />
RegFlushKey(hWkKey);<br />
RegCloseKey(hWkKey);<br />
<br />
if( lRetorn == ERROR_SUCCESS)<br />
return true;<br />
}<br />
return false;<br />
}
Hope this helps...
|
|
|
|
|
Never use KEY_ALL_ACCESS unless you want the code to be usable only by administrators.
|
|
|
|
|
Yes, you are right...
Sometimes this becomes a problem when I share code... as I make machine prototypes, and I prevent people who use my apps to reach the OS, then normally I don't have this kind of problems, I always work as an administrator.
|
|
|
|
|
|
hi
i want to access the registry hives in combo box in vc++ mfc dialog based application.
i have tried it but getting some errors.
could some body help me out.
thanks.
|
|
|
|
|
|
Hi There Every Body,
How can I hide a control's Scroll Bar?Something like ListView.
When the count of it's items exceeds a number relative to its size control shows a scoll bar.Should I Send a special Message to control?Could I do somthing with ShowWindow(BOOL)?Theoritically when a handle or poiter to a window is grabbed It can be shown or hide by ShowWindow.Any Ideas?
Kind Regards:
Ali
|
|
|
|
|
Have a look at window style WS_VSCROLL and List view style LVS_NOSCROLL .
|
|
|
|
|
thanks dear prasad,
Unfortunately it is a DOTNET project(which is written previously) and I must modify it to do such behavior.I didnt find something useful in .NET documentation and decided to use C++.Can we modify the control after it is created?whould u please post some refrence.
thanks again a lot.
Kind Regards, Ali.
|
|
|
|
|
Ali Beirami wrote: Can we modify the control after it is created?
What do you mean by control. Isn't it a MFC window.
You can modify window style after its ceation. Look for ModifyStyle,ModifyStyleEx documentation.
|
|
|
|
|
Thanks thanks,very useful.
Is there any SDK Function for changing style of a window(control )?I can NOT use MFC.
Thanks again buddy.thanks.
|
|
|
|
|
Ali Beirami wrote: Is there any SDK Function for changing style of a window
Yes, Look SetWindowLong . Your code would be on following line,
DWORD dwStyle = ::GetWindowLong(hwnd, GWL_STYLE);
if (dwStyle & WS_VSCROLL)
::SetWindowLong(hwnd, GWL_STYLE, dwStyle & ~WS_VSCROLL);
|
|
|
|