dllmain.cpp
1 // dllmain.cpp : Defines the entry point for the DLL application. 2 #include "pch.h" 3 #include "ClassFactory.h" 4 5 HINSTANCE g_hInst = NULL; 6 long g_cDllRef = 0; 7 8 // {77257004-6F25-4521-B602-50ECC6EC62A6} 9 static const GUID CLSID_StlThumbnailProvider = { 0x77257004, 0x6f25, 0x4521, { 0xb6, 0x2, 0x50, 0xec, 0xc6, 0xec, 0x62, 0xa6 } }; 10 11 BOOL APIENTRY DllMain(HMODULE hModule, 12 DWORD ul_reason_for_call, 13 LPVOID lpReserved) 14 { 15 switch (ul_reason_for_call) 16 { 17 case DLL_PROCESS_ATTACH: 18 g_hInst = hModule; 19 DisableThreadLibraryCalls(hModule); 20 break; 21 case DLL_THREAD_ATTACH: 22 case DLL_THREAD_DETACH: 23 case DLL_PROCESS_DETACH: 24 break; 25 } 26 return TRUE; 27 } 28 29 // 30 // FUNCTION: DllGetClassObject 31 // 32 // PURPOSE: Create the class factory and query to the specific interface. 33 // 34 // PARAMETERS: 35 // * rclsid - The CLSID that will associate the correct data and code. 36 // * riid - A reference to the identifier of the interface that the caller 37 // is to use to communicate with the class object. 38 // * ppv - The address of a pointer variable that receives the interface 39 // pointer requested in riid. Upon successful return, *ppv contains the 40 // requested interface pointer. If an error occurs, the interface pointer 41 // is NULL. 42 // 43 STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void** ppv) 44 { 45 HRESULT hr = CLASS_E_CLASSNOTAVAILABLE; 46 47 if (IsEqualCLSID(CLSID_StlThumbnailProvider, rclsid)) 48 { 49 hr = E_OUTOFMEMORY; 50 51 ClassFactory* pClassFactory = new ClassFactory(); 52 if (pClassFactory) 53 { 54 hr = pClassFactory->QueryInterface(riid, ppv); 55 pClassFactory->Release(); 56 } 57 } 58 59 return hr; 60 } 61 62 // 63 // FUNCTION: DllCanUnloadNow 64 // 65 // PURPOSE: Check if we can unload the component from the memory. 66 // 67 // NOTE: The component can be unloaded from the memory when its reference 68 // count is zero (i.e. nobody is still using the component). 69 // 70 STDAPI DllCanUnloadNow(void) 71 { 72 return g_cDllRef > 0 ? S_FALSE : S_OK; 73 }