⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 setupapidll.cpp

📁 reference about wireless design which is helpful to everyone
💻 CPP
字号:
/************************************************************************
 *
 *  Module:       SetupApiDll.h
 *  Long name:    CSetupApiDll class
 *  Description:  handling of the setupapi.dll
 *
 *  Runtime Env.: Win32
 *  Author(s):    Guenter Hildebrandt, Udo Eberhardt
 *  Company:      Thesycon GmbH, Ilmenau
 ************************************************************************/

// for shorter and faster windows.h
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN 1
#endif
// unicode is not supported
#ifdef UNICODE
#undef UNICODE
#endif

#include <windows.h>
#include "SetupApiDll.h"


// standard constructor
CSetupApiDll::CSetupApiDll()
{
	mDllHandle = NULL;
	InitPointers();
}


// destructor
CSetupApiDll::~CSetupApiDll()
{
	Release();
}


// init function pointers
void CSetupApiDll::InitPointers()
{
  SetupDiGetClassDevs = NULL;
  SetupDiDestroyDeviceInfoList = NULL;
  SetupDiEnumDeviceInterfaces = NULL;
  SetupDiGetDeviceInterfaceDetail = NULL;
}



// load setupapi.dll
BOOL CSetupApiDll::Load()
{
  if ( mDllHandle!=NULL ) {
    // library is already loaded
    return TRUE;
  }

  // try to load the DLL
  mDllHandle = ::LoadLibrary("setupapi.dll");
  if ( mDllHandle==NULL ) {
    // failed to load library
    return FALSE;
  }
  // DLL successfully loaded
  BOOL succ = TRUE;
  
	// try to get the function pointers we need
  SetupDiGetClassDevs = (F_SetupDiGetClassDevsA*)::GetProcAddress(mDllHandle,"SetupDiGetClassDevsA");
  if ( SetupDiGetClassDevs==NULL ) succ = FALSE;

  SetupDiDestroyDeviceInfoList = (F_SetupDiDestroyDeviceInfoList*)::GetProcAddress(mDllHandle,"SetupDiDestroyDeviceInfoList");
  if ( SetupDiDestroyDeviceInfoList==NULL ) succ = FALSE;

  SetupDiEnumDeviceInterfaces = (F_SetupDiEnumDeviceInterfaces*)::GetProcAddress(mDllHandle,"SetupDiEnumDeviceInterfaces");
  if ( SetupDiEnumDeviceInterfaces==NULL ) succ = FALSE;

  SetupDiGetDeviceInterfaceDetail = (F_SetupDiGetDeviceInterfaceDetailA*)::GetProcAddress(mDllHandle,"SetupDiGetDeviceInterfaceDetailA");
  if ( SetupDiGetDeviceInterfaceDetail==NULL ) succ = FALSE;

  // all pointers ok?
  if ( !succ ) {
    // no, release DLL
    Release();
  }
  
	return succ;
}



// release setupapi.dll
void CSetupApiDll::Release()
{
	if ( mDllHandle!=NULL ) {
		::FreeLibrary(mDllHandle);
		mDllHandle = NULL;
		InitPointers();
	}
}





/*************************** EOF **************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -