I am creating an app where I have CListBox object. I call .AddString() to add 10 string to the list. After the list is initialized, I want to update some of the string data in the list. How to do ? I reviewed all the class member of CListBox and I do not see any type of update string method. The only way I see to do this type of operation is to use Add/Delete methods. There must be a bette way Please help, so much time wasted on this class.
Hi, thank you for the reply I will look into ListView. As I found out yesterday ListBox is very good for what I am trying to do. I'm basically trying to create a window that is a comm monitor. I have 10 CAN message I receive at a very high rate 20-100ms that I want to display. With CListBox I am getting "flickering" and I know the app is probably getting tons of Window messaging !!
I got another one. This time regarding mutexes. I am using the following locking routine:
HANDLE Thread::Lock( const char* name )
// first convert const char* to LPCWSTR -> for CreateMutex()
mbstowcs_s( NULL, buffer, FILENAME_MAX, name, FILENAME_MAX-1 );
HANDLE hMutex = CreateMutex(NULL,
if (GetLastError() == ERROR_ALREADY_EXISTS)
// not really important, just for debugging
Now I found out that my locking mechanism does not work properly. And the thing is this: Thread 1 calls the Lock()-function. A Mutex is created and everything is fine. While it is locked the same thread actually (which is an error, but that´s how I found out) calls the Lock()-function again with the same name parameter. CreateMutex returns a DIFFERENT handle this time but the GetLastError query returns ERROR_ALREADY_EXISTS. But since it is a different handle WaitForSingleObject() grants access again, before the first Unlock() call occured.
So how does this work. Shouldn´t I get the same handle everytime I call CreatMutex() with the same parameters? Otherwise I get a new handle everytime and nothing is really ever locked.
The main problem here is that you are returning a local variable. In addition, every time your function is called, it creates a new mutex handle (referencing the same mutex.) You are leaking handles like crazy.
To properly use a mutex you need to first create it (and you don't need to do a conversion from a char to wide string--just call CreateMutexA.) The locking is done separately.
BTW, only use mutexes if you are synchronizing between processes or you have to have multiple waits on a lock, otherwise use critical sections.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
It is not important the handle value of CreateMutex are different or same becuase the handle will never be compared its value but only be used with WaitForXXXXXX function.
Others wrote that mutex can not lock with the same thread and this implementation may cause handle leaks.
I suggest another locking mechanism using InterlockedIncrement and InterlockedDecrement like;
I noticed the explorer properties that used to show in XP for my MFC generated files are gone in Vista. I did find something about including XML file .propdesc file to include properties that I need the file to have... Any one dealt with this before?