Solved

Events from OCX do not fire when the client app is busy with another event. [Events dropped]

Posted on 2004-09-21
3
216 Views
Last Modified: 2012-06-27
If my OCX tries to fire an event but the client app is busy with another event, the event will be lost.
I am writing the OCX in VC++ 6, this OCX will be loaded multiple times in the client app.

Here is an example of my problem.

I have 2 instances of the OCX loaded on the client app.
OCX1 fires an event -> the client app receives the event and starts processing the code in the event.
If OCX2 fires an event while the client is still processing the previous event, this event will be lost.

Another example to help visualize the problem:

OCX1 fires an event
Client runs slow code in the event such as Sleep(1000)
OCX2 fires an event before the OCX1 event finishes
Client does not receive OCX2 event

My current solution that works but i cannot use because it uses ties up the CPU.
I have a global variable called HoldEvents [all instances of the OCX can read/set this variable]
my code to fire the event now looks as follows

while(HoldEvents) {}
HoldEvents=1;
FireBlahEvent(blah);
HoldEvents=0;

Does anyone know of a better solution? I don't like the idea of a loop and i cannot add sleep in the loop to use less CPU because the events are time critical and need to be fired as soon as the client app can take them.

Joe.



0
Comment
Question by:joevm3
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
jlsjls earned 500 total points
ID: 12130922
I think the use of a Mutex could be a solution.
When you fire the event you try to get the ownership of the mutex (WaitForSingleObject(hMutex,INFINITE).
When OK, you fire the event to the application.
The application processes the event and after returning to the ocx you release the mutex.

At that moment, ocx2 can take the ownership of the mutex and can fire its data to the application. Again using procedure mentioned above.
Waiting for the mutex doesn't practically stress the CPU.

jlsjls
0
 

Author Comment

by:joevm3
ID: 12147231
how do you release the mutex?
what is hMutex... how do you initalize the mutex?

Thank you,
Joe
0
 
LVL 3

Expert Comment

by:jlsjls
ID: 12157998
* Creation of mutex (obtain handle hMutex to it) :
BOOL MakeMutex()
{
hMutex = CreateMutex(NULL,FALSE,TEXT("MyMutex"));
if (hMutex == NULL)
{
 return FALSE;
}
else
{
if (ERROR_ALREADY_EXISTS == GetLastError())
//mutex already created by other process or other thread
{
//MessageBox (NULL, TEXT("CreateMutex opened existing mutex."),TEXT("Results"), MB_OK);
}
else //new mutex was created
{                   
//MessageBox (NULL, TEXT("CreateMutex created new mutex."),TEXT("Results"), MB_OK);
}
}
return TRUE;
}

* Release the mutex
ReleaseMutex(hMutex);
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C language IDE – Compilers installation 14 78
Which IDE to use to begin C++ training? 5 70
Header of docx file 17 132
How to convert Structure to vector of byte and vice versa 5 31
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question