|
Whenever > 1 thread needs read or write access to a resource (memory/disk/database record whatever) you typically need to synchronize the access. Depending on the resource it may be possible for > 1 thread to have simultaneous read access, but there may be a bigger picture issue such as one thread writing to the resource when others are reading it. You then need to go a level higher and see whether transactions are needed etc.
Bottom line is you need to go read a good book or two on multithreaded design and implementation and all that entails. Multithreading is a whole world unto itself where deadlocks occur at the blink of an eye. And debuging multithreaded apps is way harder than single threaded apps.
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
You should guard all non constant data that you share between threads with some sort of locking mechanism. 'Manipulating' in this context, probably does mean writing. A critical section is a spin lock, it uses an atomic instruction to repeatedly test for and aquire the lock. This makes critical sections unsuitable for locking resources that may take a long time to become free, the other threads will consume cycles waiting for the lock. You should use a kernel lock in these cases, such as a mutex or event. Critical sections are only suitable for syncronising threads, not processes - they rely on shared memory.
Have a look at the boost thread library http://www.boost.org/libs/thread/doc/[^], it makes it a hell of a lot easier to write correct multithreaded programs.
Ryan.
|
|
|
|
|
Thanks mates
I am beginning to realize the many disadvantages of using multithreads.
It’s not as “perfect” as I imagined, but then again nothing ever is
Aidman » over and out
We haven't inherited Earth from our parents, instead we have borrowed her from our children; an old Indian saying.
|
|
|
|
|
There are several options out there such as drag and drop where you can change the order of a list control. So, when the user modifies your list control,
How do you save changes made to a ListCtrl by a user? (so that those changes could be loaded in at a later time)
Any suggestions would be helpful.
I wish I could type better ...
|
|
|
|
|
I'm not sure I follow the question. The ListCtrl (SysListView32) itself doesn't do anything magic to save its state or contents. You're responsible for doing that. Having said that, the ways in which you can persist the order of your list control's contents are way too numerous to get into without more specifics on what you're trying to do.
Cheers,
Tom Archer
Inside C#, Extending MFC Applications with the .NET Framework
It's better to listen to others than to speak, because I already know what I'm going to say anyway. - friend of Jörgen Sigvardsson
|
|
|
|
|
create your own ListControl Class and when the destructor is called, store all the info about the control somewhere. the registry?! I use a .mdb file and some SQL, so I can change the ListCtrl "on the fly"
|
|
|
|
|
I maintain an array of the column details that I write out to the registry for later reloading.
Michael
'War is at best barbarism...Its glory is all moonshine. It is only those who have neither fired a shot nor heard the shrieks and groans of the wounded who cry aloud for blood, more vengeance, more desolation. War is hell.' - General William Sherman, 1879
|
|
|
|
|
Hi,
how can I display system "Properties" dialog for more than one file/directory? Like in Explorer when I have selected multiple files/directories, I click right button and from context menu a select "Properties". Now I use this code:
SHELLEXECUTEINFO sei;
ZeroMemory(&sei, sizeof(sei));
sei.cbSize = sizeof(sei);
sei.hwnd = AfxGetMainWnd()->GetSafeHwnd();
sei.nShow = SW_SHOW;
sei.lpFile = filePath;
sei.lpVerb = _T("properties");
sei.fMask = SEE_MASK_INVOKEIDLIST;
ShellExecuteEx(&sei)
It works fine for single file/directory. But how can I display that dialog for more than one file/directory?
Thanks in advance.
|
|
|
|
|
Now I trid to put NULL char between file paths and double NULL at the end of list, but it also doesn't work...
|
|
|
|
|
Has anyone a exmple, to set the Quickinfo for the Statusbar dynamic during the runtime ?
I need this, cause the language of the prog could be changed during runtime too, and this is the only problem.
Also to change the font. SetFont set not the Font I want, but some internal systemfont.
Thanks in advance
Kristian
PS : I use mfc 7.0
|
|
|
|
|
Hello all
I would like to display tooltip help messages whenever user drag & drop (?)Help on a particular control of the property page.
If you any knows how to do it, please help me.
Thanks for your help.
Hari.
|
|
|
|
|
I personaly do not know. I recommend you search for "tooltips" here at codeproject (or codeguru.com), since there are several articles on the subject that may help you figure out how to accompish your goal.
INTP
|
|
|
|
|
Hi,
I had my little program running a dialog box with the callback function running perfectly. The definition of the callback function was as follows -
INT_PTR CALLBACK DlgDeviceProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
And I called it from the main program as follows -
DlgDevicehWnd = DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), hWnd, DlgDeviceProc);
I have now decided to make all of the dialog box related items into a class to clear things up. However it appears to have created a few problems for me. The class style definition and call follow respectively (the class is called CDeviceSetup, and the instance used is DeviceSetup) -
INT_PTR CALLBACK CDeviceSetup::DlgDeviceProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
DlgDevicehWnd = DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), hWnd, DeviceSetup.DlgDeviceProc);
With this setup I now get the following compilation error on the call line -
d:\projects\newdialog\dlgdevice.h(449) : error C2664: 'DialogBoxParamA' : cannot convert parameter 4 from 'int (struct HWND__ *,unsigned int,unsigned int,long)' to 'int (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long)'
Now the CALLBACK (which refers back to _stdcall) is still present but it VC++ seems to think not. Does anybody have any ideas?
Thanks in advance
Zak
|
|
|
|
|
Try making the callback function static:
static INT_PTR CALLBACK CDeviceSetup::DlgDeviceProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
Or it will never work.
INTP
|
|
|
|
|
The reason why it is not possible to make CALLBACK memberfunctions is because a 'hidden' parameter is passed to the member function. It is the 'this pointer'. A CALLBACK function is not called by any object, so no this pointer is availeble!
Solution:
you can make a Callback function and call the member function from there.
|
|
|
|
|
I want to have an array of buttons I can access as an array within the program, e.g. Button[3]->GetCheckState().
It is possible by creating individual member variables and assigning an array of pointers to these or creating the whole array within code.
Does anyone have a more elegant suggestion ?
Thanks.
Elaine
The tigress is here
|
|
|
|
|
|
Trollslayer wrote:
It is possible by creating individual member variables and assigning an array of pointers to these or creating the whole array within code.
Absolutely
When you add button objects to your dialog, add them using ClassWizard as normal, and then replace the individual buttons with an array. Instead of
CButton m_Button1;
CButton m_Button2; Use
CButton m_Buttons[2]; And then in the DoDataExchange() function, replace
DDX_Control(IDC_BUTTON1, m_Button1);
DDX_Control(IDC_BUTTON2, m_Button2); with
DDX_Control(IDC_BUTTON1, m_Buttons[0]);
DDX_Control(IDC_BUTTON2, m_Buttons[1]); Works beautifully
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
|
Now that's the nicest thankyou I've ever got
You're very welcome
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
I had a similar task but it concerned checkboxes - LOTS of checkboxes.
What I did was to edit my resource.h and make sure that all of my checkboxes had sequential ID's.
I then #define'ed CHECKBOX_START as the resource ID for the first checkbox and CHECKBOX_END for the resource ID of the last checkbox.
I then built an array of structures that held the data associated with the checkboxes.
I could then loop through and get the check states with
<br />
for(x= CHECKBOX_START, x <= CHECKBOX_END, x++)<br />
{<br />
SendDlgItemMessage(x, blah, blah, blah<br />
}<br />
I'm going to live forever or die trying!
|
|
|
|
|
is there a way to run an executable located in a memory buffer, that isn't physically on the disk?
This isn't real code, but it will give you an idea of what I am trying to do.
CRunMyNativeCode foo;
foo.run(LPVOID);
|
|
|
|
|
Beer26 wrote:
is there a way to run an executable located in a memory buffer, that isn't physically on the disk?
Maybe. But wouldn't it be easier just to write that buffer to a temp-file .exe and execute that one? What are you writing, a virus?
|
|
|
|
|
Mike Nordell wrote:
What are you writing, a virus?
It could be a software protection system where the executable is encrypted and then decrypted to memory using a key.
John
|
|
|
|
|
that's exactly right. Thanks for your superior insight and openmindedness.
|
|
|
|