這很重要
本主題中的內容和範例程式代碼已過時,目前不受支援。 它可能無法與目前的驅動程式開發工具鏈搭配使用。
您可以編譯本節中的程序代碼,以建立 UVC 擴充單元範例控件。 當您建置此專案時,您會建立Microsoft ActiveX 控件,以便與對應的應用程式搭配使用,以取得和設定擴充單元上的屬性。
若要使用 控件,您需要實作特定擴充單元功能的硬體。 或者,您可以使用 USB 模擬器。
使用下列步驟來建置 控制控制器:
安裝下列套件:
- Microsoft Windows Server 2003 Service Pack 1 (SP1) 驅動程序開發工具包 (DDK)
- Microsoft DirectX 9.0 SDK 更新 (2005 年 2 月)
- Microsoft DirectX 9.0 2005 年 2 月 SDK 額外專案
將下列主題中的範例程式代碼複製到個別檔案中。
建立 來源 檔案,如下所示:
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建立 makefile 檔案,如下所示:
############################################################################# # # 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使用Guidgen.exe工具 (包含在 Microsoft Windows SDK 中) 來建立三個 GUID:
- 使用第一個 GUID 作為擴充單元的屬性集識別碼。 將以 x 為基礎的 GUID 佔位元取代為 Xuproxy.h、Xusample.rgs、Xuplgin.inf 中的新 GUID,並在您的硬體層級擴充單元描述元中進行替換。
- 使用第二個 GUID 作為擴充單元的 IID。 在Interface.idl和Xuplgin.inf中,將 y 型 GUID 佔位符取代為新的 GUID。
- 使用第三個 GUID 作為擴充單元的類別 GUID (clsid)。 將以 z 字母為基礎的 GUID 佔位符替換為 Xuplgin.inf、Xuproxy.h 和 Xusample.rgs 中的新 GUID。
建立 Uvcxuplgn.def ,如下所示:
LIBRARY uvcxuplgn EXPORTS DllGetClassObject PRIVATE DllCanUnloadNow PRIVATE DllRegisterServer PRIVATE DllUnregisterServer PRIVATE建立 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); }建立 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)建立 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>在 WDK 建置環境中叫用
Build -cZg來建置範例。