Two points to remember before you write your Windows Media Player plug-in using the WMP public interfaces.

1. WMP interfaces are not thread safe.

2. WMP's public interfaces can be used on different threads as long as you make sure that you have marshalled the pointer correctly.

You can use CoMarshalInterThreadInterfaceInStream to marshal the WMP interfaces into a stream before you create a thread, store the stream pointer and un-marshal the pointer via CoGetInterfaceAndReleaseStream from the stream once the thread spawns up.

Example:

   1: IWMPControls *pControls;
   2:  
   3: IStream *pControlsStream; 
   4:  
   5: HRESULT hResult;
   6:  
   7: ......................................
   8:  
   9: // Marshal controls pointer for thread-safe usage.
  10:  
  11: hResult = CoMarshalInterThreadInterfaceInStream(__uuidof(IWMPControls), pControls, &pControlsStream);
  12:  
  13: .............................................................................
  14:  
  15: IWMPControls *pSafeControls;
  16:  
  17: // Unmarshall pointers before using it on a different thread
  18:  
  19: hResult = CoGetInterfaceAndReleaseStream(pControlsStream, __uuidof(IWMPControls), reinterpret_cast<LPVOID*>(&pSafeControls));

I got a LNK2001 linker error when trying to use the IID_IWMPControls from wmp.h. So I used __uuidof(IWMPControls), to retrieve the GUID of IWMPControls.

References:

1. http://msdn.microsoft.com/en-us/library/bb821452.aspx

2. http://msdn.microsoft.com/en-us/library/ms693316(VS.85).aspx

3. http://msdn.microsoft.com/en-us/library/ms691421(VS.85).aspx

-Shamik Misra

Windows SDK