1 /* 2 * PROJECT: ReactOS API tests 3 * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory 4 * PURPOSE: Test for static C++ object construction/destruction in a DLL 5 * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org> 6 */ 7 8 #include <apitest.h> 9 #include "dll_startup.h" 10 11 // we test the initial value of m_uninit variable here, so this is required 12 #ifdef __GNUC__ 13 #pragma GCC diagnostic ignored "-Wuninitialized" 14 #endif 15 16 static struct counter_values counter_values = 17 { 18 0, 0, 0, 0, 5656, 0, 0 19 }; 20 static struct counter_values *p_counter_values; 21 22 static struct init_static 23 { 24 int m_uninit; 25 int m_counter; 26 27 init_static() : 28 m_counter(2) 29 { 30 counter_values.static_construct_counter_at_startup = counter_values.static_construct_counter; 31 counter_values.m_uninit_at_startup = m_uninit; 32 counter_values.static_construct_counter++; 33 m_uninit++; 34 } 35 36 ~init_static() 37 { 38 p_counter_values->dtor_counter++; 39 } 40 } init_static; 41 42 extern "C" 43 { 44 SET_COUNTER_VALUES_POINTER SetCounterValuesPointer; 45 void 46 WINAPI 47 SetCounterValuesPointer( 48 _Out_ struct counter_values *pcv) 49 { 50 p_counter_values = pcv; 51 memcpy(pcv, &counter_values, sizeof(counter_values)); 52 } 53 54 BOOL 55 WINAPI 56 DllMain( 57 _In_ HINSTANCE hinstDLL, 58 _In_ DWORD fdwReason, 59 _In_ PVOID pvReserved) 60 { 61 if (fdwReason == DLL_PROCESS_ATTACH) 62 { 63 counter_values.m_uninit = init_static.m_uninit; 64 counter_values.m_counter = init_static.m_counter; 65 } 66 else if (fdwReason == DLL_PROCESS_DETACH) 67 { 68 p_counter_values->dtor_counter_at_detach = p_counter_values->dtor_counter; 69 } 70 return TRUE; 71 } 72 73 }