Skip to main content


Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Question about WM Encodor SDK (Read 2546 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Question about WM Encodor SDK

I am new to the Windows Media Encoder SDK and I am facing a strange problem.
I have successfully called put_AutoStop() and yet the encoder doesn't seem
to stop. I am just encoding a small PCM WAVE file to a WMA. The following is
my code. Can someone help me out?

Code: [Select]
void main()
   HRESULT hr;
   IWMEncoder* pEncoder;
   IWMEncSourceGroupCollection* pSrcGrpColl;
   IWMEncSourceGroup* pSrcGrp;
   IWMEncSource* pSrcAud;
   IWMEncFile* pFile;

   // Initialize the COM library
   hr = CoInitialize(NULL);

   // Retrieve a pointer to an IWMEncoder interface
   if (SUCCEEDED(hr))
       hr = CoCreateInstance(CLSID_WMEncoder,
           (void**) &pEncoder);

   // Set up the input
   if (SUCCEEDED(hr))
       hr = pEncoder->get_SourceGroupCollection(&pSrcGrpColl);
   if (SUCCEEDED(hr))
       hr = pSrcGrpColl->Add(CComBSTR("SG_1"), &pSrcGrp);
   if (SUCCEEDED(hr))
       hr = pSrcGrp->AddSource(WMENC_AUDIO, &pSrcAud);
   if (SUCCEEDED(hr))
       hr = pSrcAud->SetInput(CComBSTR("c:\\test\\in.wav"));
   if (SUCCEEDED(hr))
       hr = pSrcGrp->put_Profile(CComVariant("c:\\test\\in.prx"));

   // Set up the output
   if (SUCCEEDED(hr))
       hr = pEncoder->get_File(&pFile);
   if (SUCCEEDED(hr))
       hr = pFile->put_LocalFileName(CComBSTR("c:\\test\\out.wma"));

   // Set auto-stop and start encoding
   if (SUCCEEDED(hr))
       hr = pEncoder->put_AutoStop(VARIANT_TRUE);
   if (SUCCEEDED(hr))
       hr = pEncoder->PrepareToEncode(VARIANT_TRUE);
   if (SUCCEEDED(hr))
       hr = pEncoder->Start();


   // **  Infinite loop - the state never changes! **
   while (enumState == WMENC_ENCODER_RUNNING)
       printf("Current state %d.\n", enumState);

   // Stop the encoder manually

   // Release pointers.
   if (pSrcGrpColl)
       pSrcGrpColl = NULL;
   if (pSrcGrp)
       pSrcGrp = NULL;
   if (pFile)
       pFile = NULL;
   if (pSrcAud)
       pSrcAud = NULL;
   if (pEncoder)
       pEncoder = NULL;