Welcome to LEAD Support Forum Login | Register | Faq  

    LEAD Support Forum
  Resource to find answers and post technical questions about LEAD products.
Search    
   

Howto: StartConv(), console app and message loops....
Started by wresele@netway.at at 03-12-2008 4:41. Topic has 0 replies.

Print Search « Previous Thread Next Thread »
  03-12-2008, 4:41
wresele@netway.at is not online. Last active: 3/11/2008 3:37:48 PM wresele@netway.at

Not Ranked
Joined on 09-28-2004
Posts 2
Howto: StartConv(), console app and message loops....
Reply Quote

Hi,

unfortunately I had forgotten all the things I had once learned (and barely understood) about COM, STAs, Windows message loops and console apps in my former life as developer, so it took me some unnerving hours until I could finally find the simple solution how to make a simple thing work. So I want to share my stupidity - and what I learned about COM (again, the hard way) - here with you:

I was trying to use IltmmConvert->StartConv() in a simple file conversion scenario without windows gui (windows service), i.e. without windows handle, and therefore without the ability to receive notification messages (conv->SetNotifyWindow(0,0)).
This should be possible by calling StartConv() and then by repeatedly polling get_State() until the state reaches ltmmConvert_State_Stopped. 

However, when I tried it from my C++ console app, the state did never change - it always remained ltmmConvert_State_Running, but the conversion was still done successfully. Well, the solution and explanation is the following basic COM fact you should always keep in mind: any COM object in a Single Threaded Appartment (STA) can only work correctly if there is a message loop - otherwise it can lock up or may
not work at all. So I had to include a very simple message loop into my polling loop, and voila!

Here is a short code snippet from my basic example:

hr = mediaconv->StartConvert();

LONG perccomplete = 0;
LONG convstate = ltmmConvert_State_Running;
while (SUCCEEDED(hr) && (convstate == ltmmConvert_State_Running))
{
  MSG msg;
  while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) 
  { 
    TranslateMessage( &msg ); 
    DispatchMessage( &msg );
  }

  Sleep( 1000 );   // sleep for 1 secs
  hr = mediaconv->get_State( &convstate );
  if (SUCCEEDED(hr))
    hr = mediaconv->get_PercentComplete( &perccomplete );
  ... now do something with percomplete if you like ....
}

mediaconv->StopConvert();     // stop anyway...


Cheers!

Wolfgang


   Report 
Post
LEAD Support Fo... » Enduser » Capture & Conve... » Howto: StartConv(), console app and message loops....

Powered by Community Server, by Telligent Systems