|
If there are multiple instances of CBob then the mutex must be declared static so the same instance is used by all instances of CBob. Are there multiple instances of CBob?
Also you should be able to use a critical section instead of a mutex, but that is an aside.
Neville Franks, Author of ED for Windows www.getsoft.com and coming soon: Surfulater www.surfulater.com
|
|
|
|
|
There is only ever one instance of CBob.
I have looked everywhere I can think of for someone with a similar query but I haven't had any luck.
Do you think CriticalSection would be any more robust than CMutex?
|
|
|
|
|
[d3m0n] wrote:
There is only ever one instance of CBob.
I have looked everywhere I can think of for someone with a similar query but I haven't had any luck.
Do you think CriticalSection would be any more robust than CMutex?
How do you know the mutex is causing this problem? If there is only ever one instance of CBob then I suspect something else wrong.
A Mutex and CS should give the same results, however a CS is faster. Mutex's are typically used where you need to protect something across multiple processes, which you aren't doing from what I see.
I am aware of multi-threading problems which show up on multiple cpu pc's that don't show on single cpu machines.
Neville Franks, Author of ED for Windows www.getsoft.com and coming soon: Surfulater www.surfulater.com
|
|
|
|
|
"How do you know the mutex is causing this problem?"
I know this because the program crashes in the for loop which iterates through every file in the list. If at that point I look at the value of the list, it is full of garbage.
As the only place which modifies the list is on a separate thread, which is also protected by the same mutex, I cannot figure out why the HT-enabled version is allowing the list to be changed whilst it is being looped through.
|
|
|
|
|
I want to try to use the vectorization to improve the performances of my programs, but I don't have too much information about how to use the libraries. Do you know what are the libraries (if there is any) I need to include to be able to use the types like 'vector int' or whatever? If there is not do I have to use intrinsics or there is another way?
thanks
Pierre
|
|
|
|
|
You should:
#include <vector>
and initialization of a vector of ints look like this:
std::vector<int> vInt;
or
std::vector<int> vInt(numElements, initialValue);
For other data types, just replace <int> with <name_of_data_type>
|
|
|
|
|
Note if you want to improve performance consider this.
If you are removing entries within the vector frequently then this is a "slow" process. It calls copy constructors for all entries above the deleted item as it shuffles them down.
Consider using list instead in these cases.
i.e.
#include <list><br />
<br />
typedef std::list<int> TIntList;<br />
<br />
TIntList m_MyIntList;
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fuity and sweet. I'm jelly, what am I? - David Williams (Little Britain)
|
|
|
|
|
How can I call a function, given its name as a string?
|
|
|
|
|
In a map push the pointer to your function and its name as a string
and when you need to call the function just query for its pointer and pass the correct parameters.
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
I have created my project ... with VC++ + DirectShow. + MS Access..
I need to build installer for my application that can i give to my users .. to intall the application on their PC..
How can i do it ,, any Software ,, etc..
i thikn there r some scrpts with which we do ir ..
But i not have experince on these .. how can i easily build my installer
thanx
|
|
|
|
|
Try out Microsoft Visual Studio Installer
It is easy to use
and really cool.
|
|
|
|
|
Hello,
Can anyone please tell me, why "c" doesn't support nested functions
|
|
|
|
|
Do you mean the bizarre Pascal construct where you can have a function inside a function?
That is:
void func1() {
void func2(){
}
}
If that is the case, the answer is simply "because it doesn't". And a good thing it is too, support nightmare and everything It is completely unnecessary, tools converting Pascal code to C do this by creating a struct of the local variables in func1, making func2 a separate function and having the struct as an inparam to func2, if you need to convert code.
|
|
|
|
|
As has already been mentioned, there is no need. What is it that you are doing that you think requires such a construct?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
i am doing project on vc++ MFC DIALOG, where in i will be repeatedly calling the same dialog box morethan 100 times, but the problem is, that the dialog box is getting crashed(terminating or ending) after some 50 times..
what can be the problem?
|
|
|
|
|
jklhjk wrote:
what can be the problem?
Probably that you have a bug in your program. As you don't describe anything about what the dialog does, it's difficult to be more specific
Have you tried running it in debug mode, you ought to get some more info on the reason this way?
|
|
|
|
|
There is no bug in program,the same program i can run it in (c language) cmd prompt..
i have check it out by creating new dialog box ("hello")having only "OK" Buttton in it.
void CHelloDlg::OnOK()
{
// TODO: Add extra validation here
CDialog::EndDialog(IDOK);
CHelloDlg cmd(this);
cmd.DoModal();
}
after running it . keep pressing the "ok" button continously, the dialog box crashes or ends after 50 times..
|
|
|
|
|
Are you trying to do some silly version of the obnoxious JavaScript-script popping up a messagebox forever ?
Anyway, your problem might not so much be the number of times you display a dialog, but rather the amount of dialogs displayed (and parented) at the same time. But the idea of popping up a new dialog - of the same kind - in response to a press on the OK-button - is in the best case silly, in the worst downright malicious.
As it is so easy to break out of the loop, by pressing Ctrl+Alt+Del, I'll suggest what you should do anyway:
1. Remove the code in the OnOK -handler, except for the call to the base class implementation.
2. Change the code originally creating the dialog to:
while( true ) {
CHelloDlg cmd;
cmd.DoModal();
}
3. Get a new hobby.
|
|
|
|
|
Hai everyone,
I am doing a project using Listcontrol box.
In that i need some help,can any one tell me how to set font size for a particular item in a list controlbox.
for example,if i am adding a new item to the listcontrol box, it should appear bold. and other items shold be in normal font size.
Please help..
Thanks a lot. .in reading my question.
kailasam
|
|
|
|
|
|
Hi there,
I have a class called CChecklist that derives from CFormview and a checkmark image that I made invisible until the user finishes entry of another view called CFruits. How can I access IDC_CHECKMARK from CFruits class? I tried creating a object of class CChecklist to access its member function in order to change the visibility property of the control, but it gave me a run-time error. Please see below. How can I accomplish this?
void CCheckList::makeVisible()
{
GetDlgItem(IDC_CHECKMARK)->ShowWindow(TRUE);
}
void CFruits::OnOK()
{
CChecklist cl;
cl.makeVisible(); //run-time error
PostMessage(WM_COMMAND,ID_FILE_CLOSE);
}
|
|
|
|
|
makeVisible will try to find a child-control of CCheckList with the id IDC_CHECKMARK . Furthermore, you are creating an instance of CChecklist out of the blue - this instance has nothing to do with your other view/control.
You should not try to access controls between views, this makes it impossible to move one view to another application, and is considered Real Bad Programming. If you have two views, I assume that you have a single document holding both of them? In that case, the proper way to go about this is via the CDocument update-mechanism. You do this by calling CDocument::OnUpdateAllViews when you want to change stuff across view-boundaries, in (pseudo)code:
void CFirstView::SomeFunction()
{
CSomeDoc* pDoc = GetDocument();
pDoc->UpdateAllViews( this, HINT_SOME_VALUE_YOU_DEFINE );
}
and in the recipient view, you add an update handler, so:
void CSecondView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
if( lHint == HINT_SOME_VALUE_YOU_DEFINE )
{
}
}
You should also get a basic textbook on C++, you'll have to learn the difference between a class and an instance of a class, for example. Lots of grief lies ahead if you don't know this
|
|
|
|
|
I did just as you suggested but I might have missed something. Here are my code samples just in case you can pinpoint the problem.
//Main application class
BOOL CMPSApp::InitInstance()
{
/* additional code present */
CMultiDocTemplate* pFirstView = new CMultiDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CMyDoc), RUNTIME_CLASS(CMDIChildWnd),
RUNTIME_CLASS(CFirstView));
AddDocTemplate(pMHCEditDocTemplate);
CMultiDocTemplate* pFirstView = new CMultiDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CMyDoc), RUNTIME_CLASS(CMDIChildWnd),
RUNTIME_CLASS(CSecondView));
AddDocTemplate(pMHCEditDocTemplate);
}
void CFirstView::OnOK()
{
if (g_selected == TRUE)
{
CDocument* pDoc = GetDocument();
pDoc->UpdateAllViews(NULL);
}
PostMessage(WM_COMMAND, ID_FILE_CLOSE);
}
void CSecondView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
If (g_list->items.selected == 0)
{
GetDlgItem(IDC_APPLE)->ShowWindow(TRUE);
}
}
When UpdateAllViews() is called, there is only one view in the list and that is CFirstView, the calling view. Why does it not recognize the other views? Am I missing something? Thanks!
|
|
|
|
|
You are not only trying to send data between two views, they reside in different documents as well.
First, you have to get the doc templates from, the app, loop them and get the documents from each doc template. Well, it's easier to explain in code
POSITION templatePosition = AfxGetApp()->GetFirstDocTemplatePosition();
while( templatePosition != NULL )
{
CDocTemplate* documentTemplate = AfxGetApp()->GetNextDocTemplate( templatePosition );
if( documentTemplate )
{
POSITION documentPosition = documentTemplate->GetFirstDocPosition();
while( documentPosition != NULL )
{
CDocument* document = documentTemplate->GetNextDoc( documentPosition );
if( document )
document->UpdateAllViews( NULL );
}
}
}
Now, OnUpdate will be called for all views.
|
|
|
|
|
It works beautifully! Thanks Johan!
|
|
|
|