#include #include #include #include #include #include #include #include #include typedef HANDLE (WINAPI *WiaAddDeviceProc)(); typedef BOOL (WINAPI *WiaRemoveDeviceProc)(STI_DEVICE_INFORMATION *); HINSTANCE g_hInstance; bool RemoveDevice( LPCWSTR pszDeviceId ) { bool bResult = false; CComPtr pStillImage; if (SUCCEEDED(StiCreateInstance( g_hInstance, STI_VERSION, &pStillImage, NULL)) && pStillImage) { HINSTANCE hClassInstaller = LoadLibrary(TEXT("sti_ci.dll")); if (hClassInstaller) { WiaRemoveDeviceProc pfnWiaRemoveDeviceProc = reinterpret_cast(GetProcAddress(hClassInstaller, "WiaRemoveDevice")); if (pfnWiaRemoveDeviceProc) { STI_DEVICE_INFORMATION *pStiDeviceInformation = NULL; if (SUCCEEDED(pStillImage->GetDeviceInfo( const_cast(pszDeviceId), reinterpret_cast(&pStiDeviceInformation))) && pStiDeviceInformation ) { bResult = (pfnWiaRemoveDeviceProc( pStiDeviceInformation ) != FALSE); if (!bResult) { wprintf( L"WiaRemoveDeviceProc failed\n"); } LocalFree(pStiDeviceInformation); } else { wprintf( L"GetDeviceInfo on %ws failed\n", pszDeviceId ); } } else { wprintf( L"GetProcAddress on WiaRemoveDeviceProc failed\n"); } FreeLibrary( hClassInstaller ); } else { wprintf( L"LoadLibrary failed\n"); } } else { wprintf( L"StiCreateInstance failed\n"); } return bResult; } void RemoveAllDevices() { HRESULT hr = CoInitialize(NULL); if (SUCCEEDED(hr)) { CComPtr pWiaDevMgr; if (SUCCEEDED(CoCreateInstance( CLSID_WiaDevMgr, NULL, CLSCTX_LOCAL_SERVER, IID_IWiaDevMgr, (void**)&pWiaDevMgr ))) { CDeviceList DeviceList( pWiaDevMgr ); for (int i=0;i