Click here to Skip to main content
15,913,334 members
Home / Discussions / COM
   

COM

 
GeneralRe: com Pin
Anonymous24-Jan-04 2:35
Anonymous24-Jan-04 2:35 
GeneralRe: com Pin
Jörgen Sigvardsson25-Jan-04 13:38
Jörgen Sigvardsson25-Jan-04 13:38 
GeneralMake C++ Window available to an OCX Pin
Member 463423-Jan-04 11:28
Member 463423-Jan-04 11:28 
QuestionHow to delete the root storage Pin
Omar Alvi23-Jan-04 3:24
Omar Alvi23-Jan-04 3:24 
AnswerRe: How to delete the root storage Pin
Jörgen Sigvardsson25-Jan-04 13:40
Jörgen Sigvardsson25-Jan-04 13:40 
GeneralProblem with COM+ transactions in large app (long post) Pin
Juan Miguel Venturello21-Jan-04 0:52
Juan Miguel Venturello21-Jan-04 0:52 
GeneralEvent handing problem. Pin
Prakash Nadar20-Jan-04 17:57
Prakash Nadar20-Jan-04 17:57 
GeneralRe: Event handing problem. Pin
Lim Bio Liong25-Jan-04 17:15
Lim Bio Liong25-Jan-04 17:15 
Hello Prakash,

Your problem sounds like a typical Apartment-Threaded-Model COM Server/Client issue. I have provided a possible solution (jump straight to point 11 for the solution if my write-up below gets too boring) as well as an analysis of the situation :

1. Your application as well as the 3rd Party COM component is most probably Apartment-Threaded-Model based. Please let me know if this is the case.

2. When the following code is executed :

pInterface->CopyFile(....); //this is asyncronouse operation.

the 3rd party component probably starts or goes into another thread to perform its lengthy operation.

3. When the component has completed its operation, it must fire an event to your app to indicate completion of task. You have set this up by defining the CSink::OnCompleteTask() function and hooking this function to the component's connection point.

4. Everything is fine up to here. But why does your application (more precisely, the thread that calls the CopyFile() method) hang up ? Why does the CompleteTask event not fire ?

5. Quite simply, it's the endless while loop that is causing the problem :

while(CSink::bTaskComplete);

I'll explain this next.

6. When the 3rd Party COM component has completed its task, it will need to fire the CompleteTask event. This is done by CALLING the appropriate event handling function (in your case, this is the CSink::OnCompleteTask() function). The 3rd Party COM Component will already have a pointer to this function earlier on when event handling are setup.

7. Now, the very important thing is that the 3rd Party COM component will not be able to call your event handler function (CSink::OnCompleteTask()) directly. The call to the event handler function must be SERIALIZED. That is, the call request must be put into the message queue of the client application.

8. This serialization is done to ensure thread-safety and that the private data of the 3rd Party COM Component is always intact and not subject to random modification by threads running in your application.

9. Now, when the call request (to your event handler CSink::OnCompleteTask()) is put into the message queue of your app, the message queue must continue to pump in order that the call request gets executed.

10. Due to the fact that you are in a constant while loop, not only will the call request never get through, your application's GUI will also freeze up (if the thread that calls CopyFile() is also the main GUI thread).

11. To resolve the problem, try putting in a simple "make-shift" message pump after your call to pInterface->CopyFile(...) as follows :

MSG msg;

// Dispatch all windows messages in queue.
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage (&msg);
DispatchMessage(&msg);

if (CSink::bTaskComplete == FALSE)
break;
}

The above message pump will ensure that the 3rd Party COM Component's call request to your event handling function will get through. Because of this, the CSink::OnCompleteTask() function will be executed and CSink::bTaskComplete will be set to FALSE.

Once CSink::bTaskComplete is FALSE, we will break out of our while loop.

12. Give the above code a try, Prakash. And let me know how things turn out.

Best Regards,
Bio.







GeneralRe: Event handing problem. Pin
Prakash Nadar25-Jan-04 22:11
Prakash Nadar25-Jan-04 22:11 
GeneralRe: Event handing problem. Pin
Prakash Nadar26-Jan-04 19:56
Prakash Nadar26-Jan-04 19:56 
GeneralRe: Event handing problem. Pin
Lim Bio Liong26-Jan-04 20:17
Lim Bio Liong26-Jan-04 20:17 
GeneralRe: Event handing problem. Pin
Prakash Nadar27-Jan-04 5:07
Prakash Nadar27-Jan-04 5:07 
GeneralRe: Event handing problem. Pin
Maverick3-Feb-04 20:03
Maverick3-Feb-04 20:03 
GeneralRe: Event handing problem. Pin
Lim Bio Liong4-Feb-04 7:01
Lim Bio Liong4-Feb-04 7:01 
GeneralRe: Event handing problem. Pin
Maverick4-Feb-04 15:54
Maverick4-Feb-04 15:54 
GeneralRe: Event handing problem. Pin
Lim Bio Liong4-Feb-04 17:17
Lim Bio Liong4-Feb-04 17:17 
GeneralRe: Event handing problem. Pin
Lim Bio Liong4-Feb-04 19:49
Lim Bio Liong4-Feb-04 19:49 
GeneralRe: Event handing problem. Pin
Lim Bio Liong4-Feb-04 20:22
Lim Bio Liong4-Feb-04 20:22 
GeneralRe: Event handing problem. Pin
Maverick4-Feb-04 20:57
Maverick4-Feb-04 20:57 
GeneralRe: Event handing problem. Pin
Lim Bio Liong4-Feb-04 23:39
Lim Bio Liong4-Feb-04 23:39 
GeneralRe: Event handing problem. Pin
Maverick5-Feb-04 0:31
Maverick5-Feb-04 0:31 
GeneralRe: Event handing problem. Pin
Lim Bio Liong5-Feb-04 0:48
Lim Bio Liong5-Feb-04 0:48 
GeneralRe: Event handing problem. Pin
Maverick5-Feb-04 15:42
Maverick5-Feb-04 15:42 
GeneralRe: Event handing problem. Pin
Lim Bio Liong6-Feb-04 1:27
Lim Bio Liong6-Feb-04 1:27 
GeneralReg: EnumConnectionPoints and IEnumConnectionPoints Pin
Adi Narayana20-Jan-04 4:07
Adi Narayana20-Jan-04 4:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.