comctl32/listview: Draw rightmost vertical grid line when needed.
[wine] / dlls / advpack / install.c
index 1209ea8..129ea82 100644 (file)
 #include "winbase.h"
 #include "winuser.h"
 #include "winreg.h"
-#include "winver.h"
 #include "winternl.h"
 #include "winnls.h"
 #include "setupapi.h"
 #include "advpub.h"
+#include "ole2.h"
 #include "wine/debug.h"
 #include "wine/unicode.h"
 #include "advpack_private.h"
@@ -39,7 +39,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(advpack);
 #define SPAPI_ERROR     0xE0000000L
 #define SPAPI_PREFIX    0x800F0000L
 #define SPAPI_MASK      0xFFFFL
-#define HRESULT_FROM_SPAPI(x)   ((x & SPAPI_MASK) | SPAPI_PREFIX)
+#define HRESULT_FROM_SPAPI(x)   ((HRESULT)((x & SPAPI_MASK) | SPAPI_PREFIX))
 
 #define ADV_HRESULT(x)  ((x & SPAPI_ERROR) ? HRESULT_FROM_SPAPI(x) : HRESULT_FROM_WIN32(x))
 
@@ -58,7 +58,7 @@ typedef struct _ADVInfo
     BOOL need_reboot;
 } ADVInfo;
 
-typedef HRESULT (*iterate_fields_func)(HINF hinf, PCWSTR field, void *arg);
+typedef HRESULT (*iterate_fields_func)(HINF hinf, PCWSTR field, const void *arg);
 
 /* Advanced INF commands */
 static const WCHAR CheckAdminRights[] = {
@@ -75,7 +75,7 @@ static const WCHAR RunPostSetupCommands[] = {
 };
 
 /* Advanced INF callbacks */
-static HRESULT del_dirs_callback(HINF hinf, PCWSTR field, void *arg)
+static HRESULT del_dirs_callback(HINF hinf, PCWSTR field, const void *arg)
 {
     INFCONTEXT context;
     HRESULT hr = S_OK;
@@ -91,14 +91,14 @@ static HRESULT del_dirs_callback(HINF hinf, PCWSTR field, void *arg)
                                MAX_INF_STRING_LENGTH, &size))
             continue;
 
-        if (DelNodeW(directory, ADN_DEL_IF_EMPTY))
+        if (DelNodeW(directory, ADN_DEL_IF_EMPTY) != S_OK)
             hr = E_FAIL;
     }
 
     return hr;
 }
 
-static HRESULT per_user_install_callback(HINF hinf, PCWSTR field, void *arg)
+static HRESULT per_user_install_callback(HINF hinf, PCWSTR field, const void *arg)
 {
     PERUSERSECTIONW per_user;
     INFCONTEXT context;
@@ -141,7 +141,7 @@ static HRESULT per_user_install_callback(HINF hinf, PCWSTR field, void *arg)
     return SetPerUserSecValuesW(&per_user);
 }
 
-static HRESULT register_ocxs_callback(HINF hinf, PCWSTR field, void *arg)
+static HRESULT register_ocxs_callback(HINF hinf, PCWSTR field, const void *arg)
 {
     HMODULE hm;
     INFCONTEXT context;
@@ -159,21 +159,29 @@ static HRESULT register_ocxs_callback(HINF hinf, PCWSTR field, void *arg)
             continue;
 
         hm = LoadLibraryExW(buffer, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
-        if (!hm)
-            continue;
+        if (hm)
+        {
+            if (do_ocx_reg(hm, TRUE) != S_OK)
+                hr = E_FAIL;
 
-        if (do_ocx_reg(hm, TRUE))
+            FreeLibrary(hm);
+        }
+        else
             hr = E_FAIL;
 
-        FreeLibrary(hm);
+        if (FAILED(hr))
+        {
+            /* FIXME: display a message box */
+            break;
+        }
     }
 
     return hr;
 }
 
-static HRESULT run_setup_commands_callback(HINF hinf, PCWSTR field, void *arg)
+static HRESULT run_setup_commands_callback(HINF hinf, PCWSTR field, const void *arg)
 {
-    ADVInfo *info = (ADVInfo *)arg;
+    const ADVInfo *info = (const ADVInfo *)arg;
     INFCONTEXT context;
     HRESULT hr = S_OK;
     DWORD size;
@@ -188,7 +196,7 @@ static HRESULT run_setup_commands_callback(HINF hinf, PCWSTR field, void *arg)
                                MAX_INF_STRING_LENGTH, &size))
             continue;
 
-        if (launch_exe(buffer, info->working_dir, NULL))
+        if (launch_exe(buffer, info->working_dir, NULL) != S_OK)
             hr = E_FAIL;
     }
 
@@ -282,7 +290,7 @@ static HRESULT iterate_section_fields(HINF hinf, PCWSTR section, PCWSTR key,
     return hr;
 }
 
-static HRESULT check_admin_rights(ADVInfo *info)
+static HRESULT check_admin_rights(const ADVInfo *info)
 {
     INT check;
     INFCONTEXT context;
@@ -302,7 +310,7 @@ static HRESULT check_admin_rights(ADVInfo *info)
 }
 
 /* performs a setupapi-level install of the INF file */
-static HRESULT spapi_install(ADVInfo *info)
+static HRESULT spapi_install(const ADVInfo *info)
 {
     BOOL ret;
     HRESULT res;
@@ -350,8 +358,10 @@ static HRESULT adv_install(ADVInfo *info)
     if (hr != S_OK)
         return hr;
 
+    OleInitialize(NULL);
     hr = iterate_section_fields(info->hinf, info->install_sec,
                                 RegisterOCXs, register_ocxs_callback, NULL);
+    OleUninitialize();
     if (hr != S_OK)
         return hr;
 
@@ -500,10 +510,9 @@ static HRESULT install_init(LPCWSTR inf_filename, LPCWSTR install_sec,
 }
 
 /* release the install instance information */
-static void install_release(ADVInfo *info)
+static void install_release(const ADVInfo *info)
 {
-    if (info->hinf && info->hinf != INVALID_HANDLE_VALUE)
-        SetupCloseInfFile(info->hinf);
+    SetupCloseInfFile(info->hinf);
 
     HeapFree(GetProcessHeap(), 0, info->inf_path);
     HeapFree(GetProcessHeap(), 0, info->inf_filename);