Share via


Step 3: Modify Subproject Parameter and Source Files for Use with COM and Media Library (Compact 7)

3/12/2014

You must modify several of the automatically-generated subproject files to support Active Template Library (ATL) and COM objects and the Media Library. You must also register each of your custom plug-ins as a COM server, and add it to the registry by using Name-Value pairs under the Media Library application key. The Name to use for your plug-in is "Plugin#", where "#" is a unique sequential integer, and the Value is the GUID of your module. Media Library keeps the list of available media parser plug-ins in the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MLib\MetadataParserPlugins. Media Library keeps the list of available data source plug-ins in the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MLib\DataSourcePlugins.

  1. To properly register your plug-in, use your plug-in name and CLSID/GUID instead of "Plugin5" and "{FD61F5AC-4745-4994-81A1-13E3479138A3}" to replace the contents of the subproject registration entries file (MediaParserPlugin.reg) with the following code.

    ; @XIPREGION IF PLATFORM_FILES_MISC
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MLib\MetadataParserPlugins]
    "Plugin5"="{FD61F5AC-4745-4994-81A1-13E3479138A3}"
    
    [HKEY_CLASSES_ROOT\CLSID\{FD61F5AC-4745-4994-81A1-13E3479138A3}]
    @="IMLMediaParser Media Parser Plugin Class"
    
    [HKEY_CLASSES_ROOT\CLSID\{FD61F5AC-4745-4994-81A1-13E3479138A3}\InprocServer32]
    @="MediaParserPlugin.dll"
    "ThreadingModel"="Both"
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MLib\EntityExtensions]
        "WAV"="ml_Entity_music"
        "MP4"="ml_Entity_video"
    ; @XIPREGION ENDIF PLATFORM_FILES_MISC
    
  2. To make your DLL a functioning COM server, export the functions DllCanUnloadNow and DllGetClassObject. Replace the contents of the module-definition file (MediaParserPlugin.def) with the following code.

    Important

    The following code example may not contain sufficient error handling for your device. Do not include the following code in a shipping device without extensive scenario testing.

    ;
    ; Copyright (c) Microsoft Corporation.  All rights reserved.
    ;
    ; Use of this source code is subject to the terms of the Microsoft
    ; premium shared source license agreement under which you licensed
    ; this source code. If you did not accept the terms of the license
    ; agreement, you are not authorized to use this source code.
    ; For the terms of the license, see the license agreement
    ; signed by you and Microsoft.
    ; THE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR INDEMNITIES.
    ;
    ; KnownExtDll.def : Declares the module parameters.
    
    LIBRARY      "MediaParserPlugin.DLL"
    
    EXPORTS
            DllCanUnloadNow        PRIVATE
            DllGetClassObject      PRIVATE
    
  3. Replace the contents of the subproject standard include file (StdAfx.h) with the following content.

    Important

    The following code example may not contain sufficient error handling for your device. Do not include the following code in a shipping device without extensive scenario testing.

    //
    // Copyright (c) Microsoft Corporation.  All rights reserved.
    //
    //
    // Use of this sample source code is subject to the terms of the Microsoft
    // license agreement under which you licensed this sample source code. If
    // you did not accept the terms of the license agreement, you are not
    // authorized to use this sample source code. For the terms of the license,
    // please see the license agreement between you and Microsoft or, if applicable,
    // see the LICENSE.RTF on your install media or the root of your tools installation.
    // THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR INDEMNITIES.
    //
    /*************************************************************************
    
    
      Disclaimer:
    
        This code and information is provided "as is" without warranty of
        any kind, either expressed or implied, including but not limited to
        the implied warranties of merchantability and/or fitness for a
        particular purpose.
    
    */
    //
    // stdafx.h : include file for standard system include files,
    //      or project specific include files that are used frequently,
    //      but are changed infrequently
    
    #pragma once
    
    // Insert your headers here
    #define WIN32_LEAN_AND_MEAN             
    // Exclude rarely-used stuff from Windows headers
    
    #include <windows.h>
    
    #ifndef STRICT
    #define STRICT
    #endif
    
    #define _ATL_FREE_THREADED
    
    #define _ATL_STATIC_REGISTRY
    
    // including crtdbg.h here because atlbase.h defines _ASSERTE and
    // dmoimpl.h will later include crtdbg.h which also defines
    // _ASSERTE without using an ifndef wrapper.
    //#include <crtdbg.h>
    
    #include <atlbase.h>
    #include <atlcom.h>
    
    //{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
    
    #define Chk(val) { hr = (val); if (FAILED(hr)) goto Cleanup; }
    #define ChkBool(val, x) { if (!(val)) { hr = x; goto Cleanup; } }
    
    #define ENTITYLABELMUSIC    L"ml_Entity_music"
    #define ENTITYLABELVIDEO    L"ml_Entity_video"
    #define ENTITYLABELPHOTO    L"ml_Entity_photo"
    #define ENTITYLABELGENERIC  L"ml_Entity_generic"
    #define ENTITYLABELPLAYLIST L"ml_Entity_playlist"
    
    #include "mlibdll.h"
    #include "mlibdll_id.h"
    #include "mlibdll_plugin.h"
    
  4. Replace the contents of the subproject source file (MediaParserPlugin.cpp) with the following listing.

    Important

    The following code example may not contain sufficient error handling for your device. Do not include the following code in a shipping device without extensive scenario testing.

    //
    // Copyright (c) Microsoft Corporation.  All rights reserved.
    //
    //
    // Use of this sample source code is subject to the terms of the Microsoft
    // license agreement under which you licensed this sample source code. If
    // you did not accept the terms of the license agreement, you are not
    // authorized to use this sample source code. For the terms of the license,
    // please see the license agreement between you and Microsoft or, if applicable,
    // see the LICENSE.RTF on your install media or the root of your tools installation.
    // THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR INDEMNITIES.
    //
    //==========================================================================;
    //
    //  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
    //  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
    //  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
    //  PURPOSE.
    //
    //
    //--------------------------------------------------------------------------;
    //
    //                          Sample Media Parser Plug-In 
    //
    // MediaParserPlugin.cpp - Implementation of DLL exports.
    //
    //------------------------------------------------------------------------------
    
    #include "stdafx.h"
    
    class CSampleMediaParserAtlModule : public CAtlDllModuleT< CSampleMediaParserAtlModule > { };
    
    CSampleMediaParserAtlModule _AtlModule;
    
    
    BOOL APIENTRY DllMain( HANDLE hModule, 
                           DWORD  ul_reason_for_call, 
                           LPVOID lpReserved
                         )
    {
        return _AtlModule.DllMain(ul_reason_for_call, lpReserved); 
    }
    
    // Used to determine whether the DLL can be unloaded by OLE
    STDAPI DllCanUnloadNow(void)
    {
        return _AtlModule.DllCanUnloadNow();
    }
    
    // Returns a class factory to create an object of the requested type
    STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
    {
        return _AtlModule.DllGetClassObject(rclsid, riid, ppv);
    }
    

See Also

Concepts

Build and Run the Sample Media Parser
Step 1: Create the Dynamic-Link Library Subproject in Your OS Design
Step 2: Configure the Subproject Properties for Use with COM and Media Library
Step 4: Copy the Sample Implementation Source Code to Files on Your Computer
Step 5: Add the SampleMediaParser Source Code to the Subproject
Step 6: Build the OS Design and Subproject
Step 7: (Optional) Debug the Media Parser Plug-In Subproject