Building the Extension Unit Sample Control

Important

The content and sample code in this topic is outdated and currently unsupported. It may not work with the current driver development toolchain.

You can compile the code in this section to create a UVC Extension Unit Sample Control. When you build this project, you create a Microsoft ActiveX control that you can use with a corresponding application to get and set properties on an extension unit.

To use the control, you need hardware that implements the specific extension unit functionality. Alternatively, you can use a USB emulator.

Use these steps to build the control:

  1. Install the following packages:

    • Microsoft Windows Server 2003 with Service Pack 1 (SP1) Driver Development Kit (DDK)
    • Microsoft DirectX 9.0 SDK Update (February 2005)
    • Microsoft DirectX 9.0 February 2005 SDK Extras
  2. Copy the sample code from the following topics into individual files.

    Sample Interface for UVC Extension Units

    Sample Extension Unit Plug-in DLL

    Sample Registry Entry for UVC Extension Units

    Sample Application for UVC Extension Units

    Supporting Autoupdate Events with Extension Units

    Providing a UVC INF File

  3. Create a sources file as follows:

    TARGETNAME= uvcxuplgn
    TARGETTYPE= DYNLINK
    TARGETPATH= obj
    TARGETEXT=  ax
    
    DLLENTRY=_DllMainCRTStartup
    DLLBASE=0x10080000
    USE_MSVCRT=1
    
    USE_STATIC_ATL=1
    
    USER_INCLUDES= $(O)
    
    INCLUDES=
    
    SOURCES= interface.idl \
     uvcxuplgn.cpp \
             stdafx.cpp    \
             interface_i.c \
             vidcap_i.c    \
             xuproxy.cpp
    
    TARGETLIBS= \
            $(SDK_LIB_PATH)\kernel32.lib          \
            $(SDK_LIB_PATH)\user32.lib            \
            $(SDK_LIB_PATH)\gdi32.lib             \
            $(SDK_LIB_PATH)\advapi32.lib          \
            $(SDK_LIB_PATH)\comdlg32.lib          \
            $(SDK_LIB_PATH)\ole32.lib             \
            $(SDK_LIB_PATH)\oleaut32.lib          \
            $(SDK_LIB_PATH)\uuid.lib              \
            $(SDK_LIB_PATH)\comctl32.lib
    
  4. Create a makefile file as follows:

    #############################################################################
    #
    #       Copyright (C) Microsoft Corporation 1995
    #       All Rights Reserved.
    #
    #       MAKEFILE for WDM device driver kit
    #
    #############################################################################
    
    #
    # DO NOT EDIT THIS FILE!!!  Edit .\sources. if you want to add a new source
    # file to this component.  This file merely indirects to the real make file
    # that is shared by all the driver components of the Windows NT DDK
    #
    
    !if "$(WIN2K_DDKBUILD)" == ""
    !INCLUDE $(NTMAKEENV)\makefile.def
    !endif
    
  5. Use the Guidgen.exe tool (which is included in the Microsoft Windows SDK) to create three GUIDs:

    • Use the first GUID as the property set ID for your extension unit. Replace the x-based GUID placeholders with the new GUID in Xuproxy.h, Xusample.rgs,Xuplgin.inf, and in your extension unit descriptor at the hardware level.
    • Use the second GUID as the IID for your extension unit. Replace the y-based GUID placeholders with the new GUID in Interface.idl and Xuplgin.inf.
    • Use the third GUID as the class GUID (clsid) for your extension unit. Replace the z-based GUID placeholder with the new GUID in Xuplgin.inf, Xuproxy.h, and Xusample.rgs.
  6. Create Uvcxuplgn.def as follows:

    LIBRARY uvcxuplgn
    
    EXPORTS
        DllGetClassObject   PRIVATE
        DllCanUnloadNow     PRIVATE
        DllRegisterServer   PRIVATE
        DllUnregisterServer PRIVATE
    
  7. Create Uvcxuplgn.cpp as follows:

    #include "stdafx.h"
    CComModule _Module;
    #include <initguid.h>
    #include "interface.h"
    #include "xuproxy.h"
    BEGIN_OBJECT_MAP(ObjectMap)
    OBJECT_ENTRY(CLSID_ExtensionUnit, CExtension)
    END_OBJECT_MAP()
    
    STDAPI DllRegisterServer(void)
    {
        return _Module.RegisterServer(FALSE, NULL);
    }
    
    STDAPI DllUnregisterServer(void)
    {
        return _Module.UnregisterServer();
    }
    
    EXTERN_C
    BOOL
    DllMain(
        HINSTANCE   hinst,
        DWORD       dwReason,
        LPVOID      lpReserved)
    {
        switch (dwReason) {
            case DLL_PROCESS_ATTACH:
    
                _Module.Init (ObjectMap, hinst);
                break;
    
            case DLL_PROCESS_DETACH:
                _Module.Term();
                break;
        }
        return TRUE;
    }
    
    extern "C" STDMETHODIMP DllCanUnloadNow(void)
    {
        return _Module.GetLockCount()==0 ? S_OK : S_FALSE;
    }
    
    extern "C" STDAPI DllGetClassObject(
        REFCLSID    rclsid,
        REFIID      riid,
        LPVOID      *ppv)
    {
        return _Module.GetClassObject(rclsid, riid, ppv);
    }
    
  8. Create Stdafx.h as follows:

    // stdafx.h : include file for standard system include files,
    //      or project specific include files that are used frequently,
    //      but are changed infrequently
    
    #if !defined(AFX_STDAFX_H__722DC775_FE6F_42FB_BED5_E1E299976D17__INCLUDED_)
    #define AFX_STDAFX_H__722DC775_FE6F_42FB_BED5_E1E299976D17__INCLUDED_
    
    #if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000
    
    #define STRICT
    #ifndef _WIN32_WINNT
    #define _WIN32_WINNT 0x0400
    #endif
    #define _ATL_APARTMENT_THREADED
    
    #include <atlbase.h>
    //You may derive a class from CComModule and use it if you want to override
    //something, but do not change the name of _Module
    extern CComModule _Module;
    #include <atlcom.h>
    #include <atlctl.h>
    
    //{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
    
    #endif // !defined(AFX_STDAFX_H__722DC775_FE6F_42FB_BED5_E1E299976D17__INCLUDED)
    
  9. Create Stdafx.cpp as follows:

    // stdafx.cpp : source file that includes just the standard includes
    //  stdafx.pch will be the pre-compiled header
    //  stdafx.obj will contain the pre-compiled type information
    
    #include "stdafx.h"
    
    #ifdef _ATL_STATIC_REGISTRY
    #include <statreg.h>
    #include <statreg.cpp>
    #endif
    
    #include <atlimpl.cpp>
    
  10. Build the sample by invoking Build -cZg in the WDK build environment.

See also

UVC Extension Unit Code Samples

Sample Interface for UVC Extension Units

Sample Extension Unit Plug-in DLL

Sample Registry Entry for UVC Extension Units

Sample Application for UVC Extension Units

Supporting Autoupdate Events with Extension Units

Providing a UVC INF File