|
gwenael dourmap wrote:
They seem very interesting to me but I cannot access to them
You'll need recent Platform SDK - it contains required header files and libraries. You can download it from:
http://www.microsoft.com/msdownload/platformsdk/sdkupdate/
... but the download is huge.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Hello, first of all let me thank you for reading those 4 short questions, for your time and help.
>> INTRODUCTION:
I have to read and write information from a non thread safe DLL very often, imagine that we are talking about obtaining real time information from that DLL.
This DLL allow me to get errors, coordinates, what's happening in general... and set values to var's of/from another program.
I'm using WM_TIMER messages to get this information and each 10ms. the information is required.
>> QUESTIONS:
1.
What could happen if the WM_TIMER message handling time is bigger than the 10ms.?
2.
Is there any way to discard the messages received while one message is being handled?
3.
The information required from the DLL should be as recent as it could be, is this the most correct way of working?
4.
Is there any other way of requiring information continuously without getting the processor performance seriously affected?
Thank you very much.
|
|
|
|
|
AFAIR, Windows will not fill your message queue with WM_TIMER when you're processing them slowly.
Regarding questions 3 and 4:
Describe your application in more detailed fashion. Since you're worried about processing times longer than 10ms, the problem may be with slow display of information.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Hello, first of all, let me thank you for your interest.
Tomasz Sowinski wrote:
Describe your application in more detailed fashion
Here's the description:
My MVC++6 app. is only a GUI for another program (let's call it XProgram).
XProgram is a program that controls the movements of a machine it allows me to move motors, read positions with encoders, activate and deactivate actuators and read sensors state.
The DLL that I have is supplied with XProgram and it allow me to get access to what I will call an "adress" this adress can contain a value of any type (string, double, float, integer...) then I use that DLL to get and to store information from/to the XProgram.
I'm worried because of the fact that if anything fails the machine can stop working, or even worse, it can wound somebody.
The only way that I have to work is to continuously ask for the values that have to be shown, and I would like to get the best way of doing it without recompiling the code in each machine. Moreover, I would like to work as in a realtime app. discarding the messages that cannot be processed because another message of the same type is being processed.
Of course I'm still very novice, and now you know more about the way of working of my program, and about my problem too. Then, if you know another solution that can be a good deal for me, please, tell it to me.
SUMMING UP:
I obtain and send information to XProgram from my GUI program using a DLL.
I need this to be fast.
I need the processor as free as it would be possible (in order to let XProgram work).
Thank you very much.
|
|
|
|
|
Joan Murt wrote:
I need the processor as free as it would be possible (in order to let XProgram work).
This may be difficult, if you don't have the access to DLL code. In such case, you can only repeatedly check the values, which always results in high CPU usage.
If you have the access to DLL code, you can use various synchronization objects, just like Carl pointed out in his reply.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
1) Nothing could happen, besides that the update would occur less frequently. However, I believe 10 ms is too frequent if the update is made only for updating a GUI. It could probably be 250 ms (a quarter of a second), or even higher.
2/3/4) Using a WM_TIMER message to pull information is an old fashion, "16-bit" type solution, which, as you've noticed, usually affects performance. While it is possible to discard intermediate messages that have arrived during processing of another (by using the message filtering parameters of PeekMessage to remove such messages), it would be better to implement a push design in the DLL.
If you have the DLL's source code, you could change it to signal a kernel object (such as an event) as soon as new information is available. The event would typically be created by the consumer application, and be supplied to the DLL through some initialization function. The application would then wait on this object to become signaled, either in a separate worker thread (the better choice since it wouldn't lock up the GUI during update processing), or in its main thread by using MsgWaitForMultipleObjects (in order to allow for window message processing).
When signaled, the application should do whatever needs to be done for retrieving data from the DLL and updating the user interface, then return and wait for another update to occur. This way, the update thread will only be active when new data is available (which could be after 5 ms or 15 minutes).
If you need to limit the update interval (i.e., data is sometimes available more often than you'd like to update the GUI), you could create a WaitableTimer object with say a 50 ms interval, and let the thread wait for both the update event and the timer object to become signaled (WaitForMultipleObjects with bWaitAll = TRUE). This way the update cannot begin until the wait interval has expired even if data is available.
Good luck!
|
|
|
|
|
Hello, first of all let me thank you for your answer.
-----------------------------------------------------------------------------
DESCRIPTION OF THE WORKING METHOD:
-----------------------------------------------------------------------------
My MVC++6 app. is only a GUI for another program (let's call it XProgram).
XProgram is a program that controls the movements of a machine it allows me to move motors, read positions with encoders, activate and deactivate actuators and read sensors state.
The DLL that I have is supplied with XProgram and it allow me to get access to what I will call an "adress" this adress can contain a value of any type (string, double, float, integer...) then I use that DLL to get and to store information from/to the XProgram.
I'm worried because of the fact that if anything fails the machine can stop working, or even worse, it can wound somebody.
The only way that I have to work is to continuously ask for the values that have to be shown, and I would like to get the best way of doing it without recompiling the code in each machine. Moreover, I would like to work as in a realtime app. discarding the messages that cannot be processed because another message of the same type is being processed.
Of course I'm still very novice, and now you know more about the way of working of my program, and about my problem too. Then, if you know another solution that can be a good deal for me, please, tell it to me.
SUMMING UP:
I obtain and send information to XProgram from my GUI program using a DLL.
I need this to be fast.
I need the processor as free as it would be possible (in order to let XProgram work).
-----------------------------------------------------------------------------
>> NOTE
Carl Berg wrote:
it would be better to implement a push design in the DLL.
I don't have access to the DLL code.
>> QUESTION
Carl Berg wrote:
While it is possible to discard intermediate messages that have arrived during processing of another (by using the message filtering parameters of PeekMessage to remove such messages)
I have taken a look to the MSDN and I have not seen how to eliminate the same message that is being processed from the messages queue.
Could you give me an example (a little one) of how to do it?
Thank you in advance.
|
|
|
|
|
You can remove WM_TIMER messages like this at the end of your data polling function:
// Look for WM_TIMER messages
MSG msg;
while ( ::PeekMessage(&msg, NULL, WM_TIMER, WM_TIMER, PM_NOREMOVE) )
{
// m_nTimerID contains holds the ID of your timer... if you're using
// more than one timer, this removal procedure won't be fool proof.
if ( msg.wParam == (UINT)m_nTimerID )
{
// Remove the message
::PeekMessage(&msg, NULL, WM_TIMER, WM_TIMER, PM_REMOVE);
}
else break;
};
However, I wouldn't implement it like this, but instead create a worker thread that uses a Waitable Timer object (cf. CreateWaitableTimer in the Platform SDK). This way you needn't worry about removing messages from the queue, and you can change the worker thread's priority if you like. You will need to synchronize access to the variables you will be updating, but it isn't that hard.
HANDLE hWait = ::CreateWaitableTimer(...);
for ( ;; ) {
::SetWaitableTimer(...);
// You might want to use a "Quit" event object as well, created and signaled from the main thread, so you know when to exit the thread. If that's the case, use WaitForMultipleObjects instead.
DWORD dwWaitRet = ::WaitForSingleObject(hWait,...);
switch (dwWaitRet)
{
// cases...
}
}
CloseHandle(hWait);
|
|
|
|
|
|
For really tiny wait intervals such as a few ms, there are no obvious advantages, and Sleep might in fact be a better solution than creating a kernel object. However, for longer intervals the thread would remain locked until the timeout value expires, which would cause the application to look as if it was hung (and you don't want to use the dangerous TerminateThread API, since it doesn't allow for object cleanup among other unwanted side effects). In this case, it's always better to implement a solution such as the one I suggested.
|
|
|
|
|
Carl Berg wrote:
In this case, it's always better to implement a solution such as the one I suggested.
With WaitForMultipleObjects?
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Yes, exactly, one will have to use WaitForMultipleObjects in order to be able to wait on both the timer and a quit/exitthread event (and possibly other objects as well, depending on design).
If the update processing is a lengthy operation, it might be a good thing to check if the quit event has been set at a few checkpoints. This can be done using WaitForSingleObject with a zero timeout value: WaitForSingleObject(hQuitEvent, 0). If the event is set, the return value will be WAIT_OBJECT_0 (cancel update and exit thread), else it will be WAIT_TIMEOUT (continue the update process).
|
|
|
|
|
Hello,
INTRODUCTION:
First of all let me thank you very much for your help.
I think that using a thread in order to read and another one in order to write (with different priorities) will be a great solution for me.
As I had written down in the Subject of my first message I'm very novice, but I've bought a Jeffrey Richter book that talks widely about threads and I think that, with this book, I will learn how to manage and use correctly threads.
But I have a doubt:
QUESTION:
OK, I will have a thread that will get all the needed data from the XProgram, and I'll have another thread that will write data to that program too (I think that I'll need some kind of "transfer stack" that I'll will have to modify from outside the threads in order to make them work (one for each thread)...) but, now that it seems that I will simplify the fact of getting and setting data to the XProgram, I would like to know how to send that data to the place where it have to go.
Let me explain better:
>> I'll have a transfer stack for reading from the XProgram.
>> This transfer stack will contain all the variables that I have to read from the XProgram.
>> I will use some kind of filters that will avoid reading groups of variables that I don't need by the moment.
>> I will know wich group of variables have suffered a change in the XProgram.
>> I want to send all the variable groups (those in which some var. have changed) to the dialog that use that information.
-----------------------------------------------------------------------------
Which would be the best solution?
ID: 01
DESCRIPTION: Sending messages to the main application window passing the first parameter as a mask of the variables group that has been modified in order to be able to call the right update function (in other dialogs that I'll need acces to (ths is not a problem from the main window)).
COMMENT: Wouldn't be a slow method due to the messages queue?
ID: 02
DESCRIPTION: Calling an updateGUI function in each dialog that need it.
COMMENT: Does is this possible? and moreover I will need access to all those functions in all the dialogs...
ID: 03
DESCRIPTION: having the same timers that allow me to update the GUI?.
COMMENT: why do I use the two threads then?
-----------------------------------------------------------------------------
Of course I have not still readed all about threads that is in that Jeff. Richter book, but could you give me an advice about this?
Thank you again, and let me promise you that I wont annoy you again with questions without reading all about threading in the Richter's book.
|
|
|
|
|
You should probably read this article:
http://www.codeproject.com/system/simpletime.asp
|
|
|
|
|
Hello
I would like to know how we can get all sub keys under a parent key.
Say , i want to get the list of all keys in \HKEY_CURRENT_USER\SOFTWARE.Ultimately i want find the software installed in a machine.So how can i proceed?
Is there any other way like doing the same opreations using INI files?
Please do reply.
Thanks in Advance
Uday
|
|
|
|
|
udayakumar wrote:
I would like to know how we can get all sub keys under a parent key.
Use RegEnumKeyEx.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Use Instalshield .. it ll do all these kinds of job , with a predefine standard interface.
Abhishek Narula
"Learn to appreciate others ... World would appreciate you"
|
|
|
|
|
Oh I am Sorry .. I didnt read the question correctly .
RegEnumKey is the right answer.
Infact enumerate the following key
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
you ll get the list of all Uninstable Softwares
Hope that serves
Abhishek Narula
"Learn to appreciate others ... World would appreciate you"
|
|
|
|
|
I tried with this still i could not make out.
If you dont mind can u tell me where can i get the install shield code.
If you have any cah i get that.
Regards
Uday
|
|
|
|
|
hi,
i need the solution for disabling audio port, so that
if any audio format is playing i can stop it.
if anyone have idea , discuss with me.
thanks in advance.
regards
Halid
|
|
|
|
|
The problem given to me is to build a MFC app , which should have multiple child windows same as in a typical MDI , but all the views should be connected to single instance of Document class,
Something you can give a name Multiple Views Application,
that is one document and multiple views.
I am not suppose to use splitters where in I can create multiple views in CFrameWnd::OnCreateClien().
Does some one has a clue about how to go about >?
Abhishek Narula
"Learn to appreciate others ... World would appreciate you"
|
|
|
|
|
Override CMultiDocTemplate::OpenDocumentFile. This method is called when your app opens file from disk or creates new file. Before calling original implementation, check if any document is open and close it.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
No you didnt get the problem ,
I have to have 4 views opened simultaneously , in a different windows.
but all 4 view are supposed to be connected to same Doc class .
Am I able to explain it now ?
Abhishek Narula
"Learn to appreciate others ... World would appreciate you"
|
|
|
|
|
Abhishek Narula wrote:
No you didnt get the problem ,
I think I got it.
Create MDI app. When user opens/creates new document, you have to do the following:
1) ensure that previously active document is closed.
2) open additional 3 views (or whatever number is needed)
Overriden CMultiDocTemplate::OpenDocumentFile is the perfect place to put this functionality.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
When creating an active document container application, is it possible to display an active document server's menu icons? The default MFC implementation does not do this, so I'm wondering if it would be possible to (re)implement some OLE interface to achieve this. Any hints would be greatly appreciated!
|
|
|
|
|