|
For the InitializeCriticalSection LeaveCriticalSection, can more than one thread, at the same time, calling them on a same CRITICAL_SECTION structure?
If not, do I have to lock the InitializeCriticalSection and LeaveCriticalSection by using another CRITICAL_SECTION?
|
|
|
|
|
Interesting. One approach is to initialize the critical section to NULL. If you have pointers to the same raw object, then look for NULL.
Kuphryn
|
|
|
|
|
InitializeCriticalSection should be called only once by the process before the threads can use it. Those threads shouldn't call InitializeCriticalSection , but rather EnterCriticalSection or TryEnterCriticalSection in order to gain the ownership of the critical section (which may imply waiting for some other thread to release it). Once a thread obtained ownership of the critical section, and after using it, it should call LeaveCriticalSection to release it. No more than one thread will call LeaveCriticalSection at the same time, because only one thread can own the critical section at the same time (that's why they are using a critical section in the first place ).
More info can be found here[^] and here[^].
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
|
Hi,
I'm developing a namespace extension and it's going pretty well,
I've created my own shell folder and I use ShCreateFolderView to create the view.
Everything works fine, but when I try to doubleclick on one of the items, which I've given the browsable and folder flag, nothing happens!
Do I need to respond to some kind of notification for this to work? Or is there some interface I should use?
I've tried to use the IDataObject to hand back the pidl of the item, but didn't work,...
Thanks in advance...
"There is an empty room full of people who think you are creative"
|
|
|
|
|
I am trying to analyse this piece of C++ code below. It is an example code from qwt.sf.net which is an extension to QT graphics library.
I assume line 03 is calling a constructor? I have never seen it written this way. Is this a new syntax in C++? Same again in line 12. Are QApplication & QString constructors? While a & info are the references to the new constructed objects? And wtf is going on in line 14? Please can someone explain what is going on.... :S
[code]
01. int main(int argc, char **argv)
02. {
03. QApplication a(argc, argv);
04.
05. QVBox vBox;
06. vBox.setCaption("Cpu Plot");
07.
08. CpuPlot *plot = new CpuPlot(&vBox);
09. plot->setTitle("History");
10. plot->setMargin(5);
11.
12. QString info("Press the legend to en/disable a curve");
13.
14. (void)new QLabel(info, &vBox);
15. a.setMainWidget(&vBox);
16.
17. vBox.resize(500,300);
18. vBox.show();
19.
20. return a.exec();
21. }
[/code]
PS: If you are interested in seeing more, download qwt.sf.net
|
|
|
|
|
Line 14 is a call to the class's constructor. Just like Java yes?
Why couldn't line 01 do QApplication a = new QApplication(argc, argv); and line 12 do QString info = new QString("Press the legend to en/disable a curve"); ? Or are they just the same as line 14's way of creating an object?
|
|
|
|
|
kevingpo wrote:
Why couldn't line 01 do QApplication a = new QApplication(argc, argv);
Of course it could, but it is not the same thing.
I suggest you read some book on C++ before analyzing that code
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
|
|
|
|
|
kevingpo wrote:
I assume line 03 is calling a constructor
On line 03, object a is created on stack, initialized with argc and argv
kevingpo wrote:
Is this a new syntax in C++?
Nope, always been that way. You must be coming from Java or C# backgrond, right?
kevingpo wrote:
Are QApplication & QString constructors?
They are types.
kevingpo wrote:
And wtf is going on in line 14
That's a strange one indeed - an object of class QLabel is created on the heap, but without any pointer or reference to it. I wild-guess that vBox takes ownership of it, or you would have a memory leak otherwise.
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
|
|
|
|
|
kevingpo wrote:
I assume line 03 is calling a constructor?
right
these two lines above are doing the same thing :
QApplication a(argc, argv);
QApplication a = QApplication(argc, argv);
the only difference is the first one is calling the constructor implicitely, when the second one doesn't. when a constructor is declared as explicit , you cannot call it with the first way...
kevingpo wrote:
Are QApplication & QString constructors?
in C++, the constructor must have the same name of its class.
so, all depends on what line of code you are looking at.
kevingpo wrote:
While a & info are the references to the new constructed objects?
sorry, here, i don't understand your question...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
I need to convert a rtf (or doc) file to a PDF file because the meetting only accepts PDF file.
could you tell me how to covert it?
I only have Adobe read (not write), may I use it for my purpose?
thx
includeh10
|
|
|
|
|
You need the full version of Acrobat, instead of just the reader. It costs money.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
FYI, Sourceforge has PDFCreator[^] and does a very good job converting to PDF for any program that has the ability to print.
Steve
|
|
|
|
|
Try this open source program - PDFCreator[^]. It installs a "printer" that can be used by any program that has a print menu - but instead of going to a printer, it asks for the file to save the PDF output to. I recomend the version that uses AFPLGhostScript (instead of GPLGhostScript).
Steve
|
|
|
|
|
Hi,
This question probably has a simple answer, but for some reason I can't find it.
I'm still using Visual C++ 6.0. I'd like to get an autocomplete list of members when I'm working on a member function.
Let's say I'm writing
int MyClass::myMemberFunction()
{
int temp = m_ // I'd like to get a list of MyClass members to pop up here
}
I can get a list of members to pop up if I type 'this->' and hit ctrl-space, but that's too much work. I can go to class view, but even there I can't figure out how to copy a member from the list.
So, is there a nice simple way to get a list of the members of MyClass when I'm writing a member function?
Bruce
|
|
|
|
|
Odd. It's supposed to work within a class context.
Have you tried deleting the .ncb-file, thus forcing visual studio to regenerate the intellisense database?
Good music: In my rosary[^]
|
|
|
|
|
Hello,
Well I have use Visual studo C++ 6
and now I use *.net. And I need to do somethings
but I cant find where I do that.
In VS 6 I use ctrl+w and there I can add some WM_funk
but where it that now?
And I want to add my own ID_Funk like a ID_CLOCK value 1 or something but where do I do that now.
Is there anyone that can help me.
|
|
|
|
|
hiho@ll
i need a multimedia library, through which i get simply (very simply) control over a camcorder (i need: get the pixels of a stream), control some output window, which displays manipulated camcorder input (i need control over the pixels), control soundcard/microphone (get microphone stream, change it, forward it to loudspeaker)!
i know directshow, but for a beginner it's a bit heavy for that what i need
maybe there is somekind of wrapper for that, which is more easier to use
thx@ll
|
|
|
|
|
I strongly suspect that DirectShow would come with examples to do what you want.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
hiho@ll
i need to control some macromedia flash input fields of a form which is sent by https
i just want to do some login progress automatically, but it's flash an https which means
1. i don't know how to get control of flash input fields
2. just sniffer http get/post doesn't work because of https
any1 knows a workaround/solution?
thx@ll
|
|
|
|
|
I am making a monitor program for the PC. My monitor program will grab statistics about CPU and memory every 1 or 5 seconds. Then I want to store this data so I have a history and hence be able to graph this out in my GUI.
I thought about using a plain text file to store my graph data and plot it out. Plot it out manually or use gnuplot.
I found this tool called RRDTool (http://people.ee.ethz.ch/~oetiker/webtools/rrdtool/). It's a database to store time-series data. Then it will beautifully graph out your data. However it's based on executing/running the program/script. Data is input using it's own command-line script. And graph creation is done the same way using another command-line script.
Problem is, how can I get C/C++ to call or incorporate RRDTool command-line program into my GUI? Is there any way in C/C++ to call another program? I don't think there is. Plus I don't think RRDTool has developer libraries (lib*.lib, etc) for C/C++ programmers to call into their own programs.
If anyone has any suggestions/advice as to easy ways to store simple statistics (CPU & memory load), and graph them in a GUI like GTK+ (http://www.gtk.org/) I'd be very grateful.
Or does anyone know a 3rd party graph plotting library that plots to GUIs like GTK/QT/SDL?
Many thanks.
|
|
|
|
|
kevingpo wrote:
how can I get C/C++ to call or incorporate RRDTool command-line program into my GUI?
I recommend using one of these very cool CP controls instead:>>>> Also see this[^] article.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
i'm not sure, but rrdtool can also just make a .gif
i think that's the way it works
make gif and use php to show it the user of a website
so you could use it the same way, just show the gif
hmm
i think it works like that
|
|
|
|
|
hi, i am aware how to take the address of a function, but what about a bound member function? The compiler won't let me do this.
here is my code, i try to pass a function pointer to a child class to notify the parent of events:
class1.h
class class1 {<br />
public: class1(int (*)(int, int, int, int));<br />
};
class1.cpp
#include "class1.h"<br />
class1::class1(int (*notifyFunc)(int, int, int, int)) {}
class2.h
#include "class1.h"<br />
<br />
class class2 {<br />
private:<br />
class1 *client;<br />
int TheNotifyFunc(int, int, int, int);<br />
public:<br />
class2();<br />
};
class2.cpp
#include "class2.h"<br />
<br />
class2::class2() {<br />
client = new class1(this->TheNotifyFunc);
}<br />
<br />
int class2::TheNotifyFunc(int, int, int, int) {<br />
return 0;<br />
}
main.cpp
#include "class2.h"<br />
<br />
void main() {<br />
new class2();<br />
}
my compiler error is:
Compiling...<br />
class2.cpp<br />
class2.cpp(4) : error C2664: 'class1::class1(int (__cdecl *)(int,int,int,int))' : cannot convert parameter 1 from 'int (int,int,int,int)' to 'int (__cdecl *)(int,int,int,int)'<br />
None of the functions with this name in scope match the target type
any workarounds?
|
|
|
|
|
I don't think the way you are trying to do it will work anyway...
Why do you want to pass "a bound member function" in the first place? Presumably because you want/need that function to access some data of a particular instance of class2, isn't it? Non static class member functions include an implicit first parameter named this , which is a pointer to the particular instance for which the method is invoked. So int TheNotifyFunc(int, int, int, int) is actually int TheNotifyFunc(class2* this, int, int, int, int); , although the language hides that detail. Then, how do you intend to pass the this parameter from class1 when you need to invoke the function?
If you don't actually need to access instance data in TheNotifyFunc(), then you should declare it as static.
If you do need to access instance data, you could, at first, program something like this:
#pragma once
class Parent;
class Child
{
private:
Parent* m_pParent;
public:
Child(Parent* pParent)
void SomeChildFunction();
};
#include "child.h"
#include "parent.h"
Child::Child(Parent* pParent)
: m_pParent(pParent)
{
}
void Child::SomeChildFunction()
{
if (m_pParent)
m_pParent->OnChildEvent(n1, n2, n3, n4);
}
#pragma once
class Child;
class Parent
{
private:
Child* m_pChild;
public:
Parent();
~Parent();
int OnChildEvent(int n1, int n2, int n3, int n4);
};
#include "parent.h"
#include "child.h"
Parent::Parent()
{
m_pChild = new Child(this);
}
Parent::~Parent()
{
delete m_pChild;
}
int Parent::OnChildEvent(int n1, int n2, int n3, int n4)
{
}
However, the fact that you were trying to use generic notifier functions rather than plain old object pointers and method calls, makes me think this approach might not be appropriate in your case. Indeed, what if you need your Child objects to have parents of different non related classes? In other words, what if you don't want your Child class to be tied (coupled) to a particular Parent class? That is, the only thing your Child class needs to know about (and depend on) from its "parent", is a way to send it some specific notification.
If that is the case, I humbly suggest you read this article[^], and then program something like this:
#pragma once
#include "cppinterfaces.h"
DeclareInterface(IChildEventTarget)
virtual int OnChildEvent(int n1, int n2, int n3, int n4) = 0;
EndInterface(IChildEventTarget)
#pragma once
interface IChildEventTarget;
class Child
{
private:
IChildEventTarget* m_pEventTarget;
public:
Child(IChildEventTarget* pEventTarget)
void SomeChildFunction();
};
#include "child.h"
#include "IChildEventTarget.h"
Child::Child(IChildEventTarget* pEventTarget)
: m_pEventTarget(pEventTarget)
{
}
void Child::SomeChildFunction()
{
if (m_pEventTarget)
m_pEventTarget->OnChildEvent(n1, n2, n3, n4);
}
#pragma once
#include "IChildEventTarget.h"
class Child;
class Parent : implements IChildEventTarget.h
{
private:
Child* m_pChild;
public:
Parent();
~Parent();
int OnChildEvent(int n1, int n2, int n3, int n4);
};
This is a much cleaner design, because your Child does not depend anymore in any specific "parent" implementation, which is what I think you was looking for with the generic function pointer. The child class does not need to be modified (not even recompiled) because of irrelevant changes in the parent class, and any other unrelated class can act as a parent as long as it implements the IChildEventTarget interface.
I've found this interface approach very useful in many cases, not just for events and event targets. However, for this specific case, you should also take a look at this excellent article[^] by Don Clugston[^].
Hope that helps,
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|