生成扩展单元示例控件

重要

本主题中的内容和示例代码已过时,目前不受支持。 它可能不适用于当前的驱动程序开发工具链。

可以编译本部分中的代码以创建 UVC 扩展单元示例控件。 生成此项目时,将创建一个 Microsoft ActiveX 控件,该控件可与相应的应用程序一起使用,以获取和设置扩展单元的属性。

若要使用 控件,需要实现特定扩展单元功能的硬件。 或者,可以使用 USB 仿真器。

使用以下步骤生成控件:

  1. 安装以下包:

    • Microsoft Windows Server 2003 service Pack 1 (SP1) Driver Development Kit (DDK)
    • Microsoft DirectX 9.0 SDK 更新 (2005 年 2 月)
    • Microsoft DirectX 9.0 2005 年 2 月 SDK 附加内容
  2. 将以下主题中的示例代码复制到单个文件中。

    UVC 扩展单元的示例接口

    示例扩展单元插件 DLL

    UVC 扩展单元的示例注册表项

    UVC 扩展单元的示例应用程序

    支持扩展单元的自动更新事件

    提供 UVC INF 文件

  3. 按如下所示创建 源文件

    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. 按如下所示创建 生成文件 文件:

    #############################################################################
    #
    #       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. 使用Microsoft Windows SDK) 中包含的Guidgen.exe工具 (创建三个 GUID:

    • 使用第一个 GUID 作为扩展单元的属性集 ID。 将基于 x 的 GUID 占位符替换为 Xuproxy.h、Xusample.rgs、Xuplgin.inf 和硬件级别的扩展单元描述符中的新 GUID。
    • 使用第二个 GUID 作为扩展单元的 IID。 将基于 y 的 GUID 占位符替换为 Interface.idlXuplgin.inf 中的新 GUID
    • 使用第三个 GUID 作为扩展单元的类 GUID (clsid) 。 将基于 z 的 GUID 占位符替换为 Xuplgin.inf、Xuproxy.hXusample.rgs 中的新 GUID。
  6. 创建 Uvcxuplgn.def ,如下所示:

    LIBRARY uvcxuplgn
    
    EXPORTS
        DllGetClassObject   PRIVATE
        DllCanUnloadNow     PRIVATE
        DllRegisterServer   PRIVATE
        DllUnregisterServer PRIVATE
    
  7. 创建 Uvcxuplgn.cpp ,如下所示:

    #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. 创建 Stdafx.h ,如下所示:

    // 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. 按如下所示创建 Stdafx.cpp

    // 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. 通过在 WDK 生成环境中调用 Build -cZg 来生成示例。

另请参阅

UVC 扩展单元代码示例

UVC 扩展单元的示例接口

示例扩展单元插件 DLL

UVC 扩展单元的示例注册表项

UVC 扩展单元的示例应用程序

支持扩展单元的自动更新事件

提供 UVC INF 文件