Search code examples
c++mfcvisual-studio-2019activexwindows-media-player

Embedding Windows Media Player in MFC


I am trying to embed WMP in a newly created MFC dialog based application using Visual Studio 2019. These are the steps I'm following:

  1. Create new project
  2. Go to resource view and click Insert ActiveX Control
  3. Select Windows Media Player and click OK
  4. Change the newly created WMP element's ID to something less general, like WMP_Player
  5. Right click the WMP element and select Add Variable
  6. I set the variable name something like m_wmp
  7. The new variable is created and CWMP_Player.h and CWMP_Player.cpp are added to the project.

I try to build the project and it fails. Inside CWMP_Player.h there are 354 errors like:

Severity Code Description Project File Line Suppression State

Error C2535 BOOL CWMP_Player::get_isAvailable(LPCTSTR): member function already defined or declared WinMediaPl

Error C2377 BOOL: redefinition; typedef cannot be overloaded with any other symbol WinMediaPl

Error C2660 CWMP_Player::InvokeHelper: function does not take 5 arguments WinMediaPl

While the CWMP_Player.cpp is almost empty, with only a couple of includes (one which is the pch.h) and just this line:

IMPLEMENT_DYNCREATE(CWMP_Player, CWnd)

Did I forget a step? Should I include something in this file or another?


Solution

  • In my opinion, the code automatically added in the class file added by VS2019 conflicts with the definition in WinMediaPl. After comparing the code automatically added by VS2017 and VS2019, I find that the automatically added code below is redundant in CWMP_Player.h or other .h.

    // Operations
    public:
    // IWMPPlaylist
    
    // Functions
    //
    
        long get_count()
        {
            long result;
            InvokeHelper(0xC9, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, nullptr);
            return result;
        }
        CString get_name()
        {
            CString result;
            InvokeHelper(0xCA, DISPATCH_PROPERTYGET, VT_BSTR, (void*)&result, nullptr);
            return result;
        }
    
    ...
    
        VARIANT getItemInfoByType(long lCollectionIndex, LPCTSTR bstrType, LPCTSTR bstrLanguage, long lAttributeIndex)
        {
            VARIANT result;
            static BYTE parms[] = VTS_I4 VTS_BSTR VTS_BSTR VTS_I4 ;
            InvokeHelper(0x5AE, DISPATCH_METHOD, VT_VARIANT, (void*)&result, parms, lCollectionIndex, bstrType, bstrLanguage, lAttributeIndex);
            return result;
        }
    

    So, you could comment them out.