20#if !defined WIN32_LEAN_AND_MEAN
21# define WIN32_LEAN_AND_MEAN
30#define CHART_COMPONENT 1
31#define DRAW_COMPONENT 2
32#define IMPRESS_COMPONENT 4
33#define CALC_COMPONENT 8
34#define WRITER_COMPONENT 16
35#define MATH_COMPONENT 32
37typedef int ( __stdcall * DllNativeRegProc ) (
int,
BOOL,
BOOL,
const wchar_t* );
40static bool UnicodeEquals(
wchar_t const * pStr1,
wchar_t const * pStr2 )
42 if ( pStr1 ==
nullptr && pStr2 ==
nullptr )
44 else if ( pStr1 ==
nullptr || pStr2 ==
nullptr )
47 while( *pStr1 == *pStr2 && *pStr1 && *pStr2 )
53 return ( *pStr1 == 0 && *pStr2 == 0 );
57static void RegisterActiveXNative(
const wchar_t* pActiveXPath,
int nMode,
bool InstallForAllUser,
bool InstallFor64Bit )
59 HINSTANCE hModule = LoadLibraryExW( pActiveXPath,
nullptr, LOAD_WITH_ALTERED_SEARCH_PATH );
62 DllNativeRegProc pNativeProc =
reinterpret_cast<DllNativeRegProc
>(GetProcAddress( hModule,
"DllRegisterServerNative" ));
63 if( pNativeProc!=
nullptr )
65 int nLen = wcslen( pActiveXPath );
66 int nRemoveLen = strlen(
"\\so_activex.dll" );
67 if ( nLen > nRemoveLen )
69 wchar_t*
pProgramPath =
static_cast<wchar_t*
>( malloc( (nLen - nRemoveLen + 1) *
sizeof(
wchar_t) ) );
71 wcsncpy(
pProgramPath, pActiveXPath, nLen - nRemoveLen );
74 ( *pNativeProc )( nMode, InstallForAllUser, InstallFor64Bit,
pProgramPath );
80 FreeLibrary( hModule );
85static void UnregisterActiveXNative(
const wchar_t* pActiveXPath,
int nMode,
bool InstallForAllUser,
bool InstallFor64Bit )
87 HINSTANCE hModule = LoadLibraryExW( pActiveXPath,
nullptr, LOAD_WITH_ALTERED_SEARCH_PATH );
90 DllNativeUnregProc pNativeProc =
reinterpret_cast<DllNativeUnregProc
>(GetProcAddress( hModule,
"DllUnregisterServerNative" ));
91 if( pNativeProc!=
nullptr )
92 ( *pNativeProc )( nMode, InstallForAllUser, InstallFor64Bit );
94 FreeLibrary( hModule );
99static bool GetMsiPropW( MSIHANDLE hMSI,
const wchar_t* pPropName,
wchar_t** ppValue )
102 if ( MsiGetPropertyW( hMSI, pPropName,
const_cast<wchar_t *
>(L
""), &sz ) == ERROR_MORE_DATA )
105 DWORD nbytes = sz *
sizeof( wchar_t );
106 wchar_t* buff =
static_cast<wchar_t*
>( malloc( nbytes ) );
108 ZeroMemory( buff, nbytes );
109 MsiGetPropertyW( hMSI, pPropName, buff, &sz );
121 wchar_t* pProgPath =
nullptr;
122 if (
GetMsiPropW( hMSI, L
"INSTALLLOCATION", &pProgPath ) && pProgPath )
124 int nLen = wcslen( pProgPath );
125 *ppActiveXPath =
static_cast<wchar_t*
>( malloc( (nLen + 23) *
sizeof(
wchar_t) ) );
126 wcsncpy( *ppActiveXPath, pProgPath, nLen );
127 wcsncpy( (*ppActiveXPath) + nLen, L
"program\\so_activex.dll", 22 );
128 (*ppActiveXPath)[nLen+22] = 0;
139static bool GetDelta( MSIHANDLE hMSI,
int& nOldInstallMode,
int& nInstallMode,
int& nDeinstallMode )
146 INSTALLSTATE current_state;
147 INSTALLSTATE future_state;
149 if ( ERROR_SUCCESS == MsiGetFeatureStateW( hMSI, L
"gm_p_Wrt_Bin", ¤t_state, &future_state ) )
152 if ( current_state == INSTALLSTATE_LOCAL )
155 if ( future_state == INSTALLSTATE_LOCAL
156 || ( current_state == INSTALLSTATE_LOCAL && future_state == INSTALLSTATE_UNKNOWN ) )
158 else if ( current_state == INSTALLSTATE_LOCAL && future_state == INSTALLSTATE_ABSENT )
166 if ( ERROR_SUCCESS == MsiGetFeatureStateW( hMSI, L
"gm_p_Calc_Bin", ¤t_state, &future_state ) )
169 if ( current_state == INSTALLSTATE_LOCAL )
172 if ( future_state == INSTALLSTATE_LOCAL
173 || ( current_state == INSTALLSTATE_LOCAL && future_state == INSTALLSTATE_UNKNOWN ) )
175 else if ( current_state == INSTALLSTATE_LOCAL && future_state == INSTALLSTATE_ABSENT )
183 if ( ERROR_SUCCESS == MsiGetFeatureStateW( hMSI, L
"gm_p_Draw_Bin", ¤t_state, &future_state ) )
186 if ( current_state == INSTALLSTATE_LOCAL )
189 if ( future_state == INSTALLSTATE_LOCAL
190 || ( current_state == INSTALLSTATE_LOCAL && future_state == INSTALLSTATE_UNKNOWN ) )
192 else if ( current_state == INSTALLSTATE_LOCAL && future_state == INSTALLSTATE_ABSENT )
200 if ( ERROR_SUCCESS == MsiGetFeatureStateW( hMSI, L
"gm_p_Impress_Bin", ¤t_state, &future_state ) )
203 if ( current_state == INSTALLSTATE_LOCAL )
206 if ( future_state == INSTALLSTATE_LOCAL
207 || ( current_state == INSTALLSTATE_LOCAL && future_state == INSTALLSTATE_UNKNOWN ) )
209 else if ( current_state == INSTALLSTATE_LOCAL && future_state == INSTALLSTATE_ABSENT )
217 if ( ERROR_SUCCESS == MsiGetFeatureStateW( hMSI, L
"gm_p_Math_Bin", ¤t_state, &future_state ) )
220 if ( current_state == INSTALLSTATE_LOCAL )
223 if ( future_state == INSTALLSTATE_LOCAL
224 || ( current_state == INSTALLSTATE_LOCAL && future_state == INSTALLSTATE_UNKNOWN ) )
226 else if ( current_state == INSTALLSTATE_LOCAL && future_state == INSTALLSTATE_ABSENT )
240 bool bResult =
false;
241 wchar_t* pVal =
nullptr;
242 if (
GetMsiPropW( hMSI, L
"ALLUSERS", &pVal ) && pVal )
254 bool bResult =
false;
255 wchar_t* pVal =
nullptr;
256 if (
GetMsiPropW( hMSI, L
"VersionNT64", &pVal ) && pVal )
265extern "C" __declspec(dllexport) UINT __stdcall InstallActiveXControl( MSIHANDLE hMSI )
267 INSTALLSTATE current_state;
268 INSTALLSTATE future_state;
270 if ( ERROR_SUCCESS == MsiGetFeatureStateW( hMSI, L
"gm_o_Activexcontrol", ¤t_state, &future_state ) )
272 int nOldInstallMode = 0;
273 int nInstallMode = 0;
274 int nDeinstallMode = 0;
278 wchar_t* pActiveXPath =
nullptr;
280 &&
GetDelta( hMSI, nOldInstallMode, nInstallMode, nDeinstallMode ) )
282 if ( future_state == INSTALLSTATE_LOCAL
283 || ( current_state == INSTALLSTATE_LOCAL && future_state == INSTALLSTATE_UNKNOWN ) )
287 if ( current_state == INSTALLSTATE_LOCAL && nDeinstallMode )
293 else if ( current_state == INSTALLSTATE_LOCAL && future_state == INSTALLSTATE_ABSENT )
295 if ( nOldInstallMode )
301 free( pActiveXPath );
308 return ERROR_SUCCESS;
312extern "C" __declspec(dllexport) UINT __stdcall DeinstallActiveXControl( MSIHANDLE hMSI )
314 INSTALLSTATE current_state;
315 INSTALLSTATE future_state;
317 if ( ERROR_SUCCESS == MsiGetFeatureStateW( hMSI, L
"gm_o_Activexcontrol", ¤t_state, &future_state ) )
319 wchar_t* pActiveXPath =
nullptr;
320 if ( current_state == INSTALLSTATE_LOCAL &&
GetActiveXControlPath( hMSI, &pActiveXPath ) && pActiveXPath )
337 free( pActiveXPath );
341 return ERROR_SUCCESS;
static bool GetDelta(MSIHANDLE hMSI, int &nOldInstallMode, int &nInstallMode, int &nDeinstallMode)
const wchar_t *typedef BOOL
static bool MakeInstallForAllUsers(MSIHANDLE hMSI)
static bool GetActiveXControlPath(MSIHANDLE hMSI, wchar_t **ppActiveXPath)
const wchar_t *typedef int(__stdcall *DllNativeUnregProc)(int
static bool MakeInstallFor64Bit(MSIHANDLE hMSI)
static bool UnicodeEquals(wchar_t const *pStr1, wchar_t const *pStr2)
static void UnregisterActiveXNative(const wchar_t *pActiveXPath, int nMode, bool InstallForAllUser, bool InstallFor64Bit)
static bool GetMsiPropW(MSIHANDLE hMSI, const wchar_t *pPropName, wchar_t **ppValue)
static void RegisterActiveXNative(const wchar_t *pActiveXPath, int nMode, bool InstallForAllUser, bool InstallFor64Bit)
__declspec(dllexport) UINT __stdcall InstallActiveXControl(MSIHANDLE hMSI)
#define IMPRESS_COMPONENT
EXTERN_C BOOL BOOL const wchar_t * pProgramPath