From: Zebediah Figura zfigura@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/setupapi/tests/Makefile.in | 6 ++- dlls/setupapi/tests/install.c | 90 ++++++++++++++++++++++++++++++++ dlls/setupapi/tests/selfreg.c | 50 ++++++++++++++++++ dlls/setupapi/tests/selfreg.spec | 2 + 4 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 dlls/setupapi/tests/selfreg.c create mode 100644 dlls/setupapi/tests/selfreg.spec
diff --git a/dlls/setupapi/tests/Makefile.in b/dlls/setupapi/tests/Makefile.in index 83f751c7dbd..df7c6687875 100644 --- a/dlls/setupapi/tests/Makefile.in +++ b/dlls/setupapi/tests/Makefile.in @@ -1,5 +1,7 @@ TESTDLL = setupapi.dll -IMPORTS = advapi32 cabinet setupapi shell32 uuid user32 +IMPORTS = advapi32 cabinet ole32 setupapi shell32 uuid user32 + +selfreg_IMPORTS = uuid advapi32 ole32
SOURCES = \ coinst.c \ @@ -11,6 +13,8 @@ SOURCES = \ misc.c \ parser.c \ query.c \ + selfreg.c \ + selfreg.spec \ setupapi.rc \ setupcab.c \ stringtable.c diff --git a/dlls/setupapi/tests/install.c b/dlls/setupapi/tests/install.c index fd10fd91332..b918bb21f60 100644 --- a/dlls/setupapi/tests/install.c +++ b/dlls/setupapi/tests/install.c @@ -54,6 +54,24 @@ static char CURR_DIR[MAX_PATH]; * Helpers */
+static void load_resource(const char *name, const char *filename) +{ + DWORD written; + HANDLE file; + HRSRC res; + void *ptr; + + file = CreateFileA(filename, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0); + ok(file != INVALID_HANDLE_VALUE, "file creation failed, at %s, error %d\n", filename, GetLastError()); + + res = FindResourceA(NULL, name, "TESTDLL"); + ok( res != 0, "couldn't find resource\n" ); + ptr = LockResource( LoadResource( GetModuleHandleA(NULL), res )); + WriteFile( file, ptr, SizeofResource( GetModuleHandleA(NULL), res ), &written, NULL ); + ok( written == SizeofResource( GetModuleHandleA(NULL), res ), "couldn't write resource\n" ); + CloseHandle( file ); +} + static void create_inf_file(LPCSTR filename, const char *data) { DWORD res; @@ -2040,6 +2058,77 @@ static void test_start_copy(void) delete_file("dst/"); }
+static void test_register_dlls(void) +{ + static const char inf_data[] = "[Version]\n" + "Signature="$Chicago$"\n" + "[DefaultInstall]\n" + "RegisterDlls=register_section\n" + "UnregisterDlls=register_section\n" + "[register_section]\n" + "40000,,winetest_selfreg.dll,1\n"; + + void *context = SetupInitDefaultQueueCallbackEx(NULL, INVALID_HANDLE_VALUE, 0, 0, 0); + char path[MAX_PATH]; + HRESULT hr; + HINF hinf; + BOOL ret; + HKEY key; + LONG l; + + create_inf_file("test.inf", inf_data); + sprintf(path, "%s\test.inf", CURR_DIR); + hinf = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL); + ok(hinf != INVALID_HANDLE_VALUE, "Failed to open INF file, error %#x.\n", GetLastError()); + + load_resource("selfreg.dll", "winetest_selfreg.dll"); + ret = SetupSetDirectoryIdA(hinf, 40000, CURR_DIR); + ok(ret, "Failed to set directory ID, error %u.\n", GetLastError()); + + RegDeleteKeyA(HKEY_CURRENT_USER, "winetest_setupapi_selfreg"); + + ret = SetupInstallFromInfSectionA(NULL, hinf, "DefaultInstall", SPINST_REGSVR, + NULL, "C:\", 0, SetupDefaultQueueCallbackA, context, NULL, NULL); + ok(ret, "Failed to install, error %#x.\n", GetLastError()); + + l = RegOpenKeyA(HKEY_CURRENT_USER, "winetest_setupapi_selfreg", &key); + todo_wine ok(!l, "Got error %u.\n", l); + RegCloseKey(key); + + ret = SetupInstallFromInfSectionA(NULL, hinf, "DefaultInstall", SPINST_UNREGSVR, + NULL, "C:\", 0, SetupDefaultQueueCallbackA, context, NULL, NULL); + ok(ret, "Failed to install, error %#x.\n", GetLastError()); + + l = RegOpenKeyA(HKEY_CURRENT_USER, "winetest_setupapi_selfreg", &key); + ok(l == ERROR_FILE_NOT_FOUND, "Got error %u.\n", l); + + hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + ret = SetupInstallFromInfSectionA(NULL, hinf, "DefaultInstall", SPINST_REGSVR, + NULL, "C:\", 0, SetupDefaultQueueCallbackA, context, NULL, NULL); + ok(ret, "Failed to install, error %#x.\n", GetLastError()); + + l = RegOpenKeyA(HKEY_CURRENT_USER, "winetest_setupapi_selfreg", &key); + ok(!l, "Got error %u.\n", l); + RegCloseKey(key); + + ret = SetupInstallFromInfSectionA(NULL, hinf, "DefaultInstall", SPINST_UNREGSVR, + NULL, "C:\", 0, SetupDefaultQueueCallbackA, context, NULL, NULL); + ok(ret, "Failed to install, error %#x.\n", GetLastError()); + + l = RegOpenKeyA(HKEY_CURRENT_USER, "winetest_setupapi_selfreg", &key); + ok(l == ERROR_FILE_NOT_FOUND, "Got error %u.\n", l); + + CoUninitialize(); + + SetupCloseInfFile(hinf); + ret = DeleteFileA("test.inf"); + ok(ret, "Failed to delete INF file, error %u.\n", GetLastError()); + ret = DeleteFileA("winetest_selfreg.dll"); + ok(ret, "Failed to delete test DLL, error %u.\n", GetLastError()); +} + START_TEST(install) { char temp_path[MAX_PATH], prev_path[MAX_PATH]; @@ -2069,6 +2158,7 @@ START_TEST(install) test_close_queue(); test_install_file(); test_start_copy(); + test_register_dlls();
UnhookWindowsHookEx(hhook);
diff --git a/dlls/setupapi/tests/selfreg.c b/dlls/setupapi/tests/selfreg.c new file mode 100644 index 00000000000..f687990f3bc --- /dev/null +++ b/dlls/setupapi/tests/selfreg.c @@ -0,0 +1,50 @@ +/* + * DLL for testing COM self-registration + * + * Copyright 2020 Zebediah Figura for CodeWeavers + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#define COBJMACROS +#include "msxml.h" + +HRESULT WINAPI DllRegisterServer(void) +{ + IUnknown *unk; + HKEY key; + + if (CoCreateInstance(&CLSID_XMLDocument, NULL, CLSCTX_INPROC_SERVER, + &IID_IUnknown, (void **)&unk) == S_OK) + { + RegCreateKeyA(HKEY_CURRENT_USER, "winetest_setupapi_selfreg", &key); + RegCloseKey(key); + IUnknown_Release(unk); + } + return S_OK; +} + +HRESULT WINAPI DllUnregisterServer(void) +{ + IUnknown *unk; + + if (CoCreateInstance(&CLSID_XMLDocument, NULL, CLSCTX_INPROC_SERVER, + &IID_IUnknown, (void **)&unk) == S_OK) + { + RegDeleteKeyA(HKEY_CURRENT_USER, "winetest_setupapi_selfreg"); + IUnknown_Release(unk); + } + return S_OK; +} diff --git a/dlls/setupapi/tests/selfreg.spec b/dlls/setupapi/tests/selfreg.spec new file mode 100644 index 00000000000..0f9b07355f7 --- /dev/null +++ b/dlls/setupapi/tests/selfreg.spec @@ -0,0 +1,2 @@ +@ stdcall -private DllRegisterServer() +@ stdcall -private DllUnregisterServer()
From: Zebediah Figura zfigura@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/setupapi/install.c | 14 ++++++++++++++ dlls/setupapi/tests/install.c | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/dlls/setupapi/install.c b/dlls/setupapi/install.c index e1667541680..86390b5a41c 100644 --- a/dlls/setupapi/install.c +++ b/dlls/setupapi/install.c @@ -1125,6 +1125,7 @@ BOOL WINAPI SetupInstallFromInfSectionW( HWND owner, HINF hinf, PCWSTR section, if (flags & SPINST_REGSVR) { struct register_dll_info info; + HRESULT hr;
info.unregister = FALSE; info.modules_size = 0; @@ -1142,14 +1143,21 @@ BOOL WINAPI SetupInstallFromInfSectionW( HWND owner, HINF hinf, PCWSTR section, else return FALSE;
+ hr = CoInitialize(NULL); + ret = iterate_section_fields( hinf, section, RegisterDlls, register_dlls_callback, &info ); for (i = 0; i < info.modules_count; i++) FreeLibrary( info.modules[i] ); + + if (SUCCEEDED(hr)) + CoUninitialize(); + HeapFree( GetProcessHeap(), 0, info.modules ); if (!ret) return FALSE; } if (flags & SPINST_UNREGSVR) { struct register_dll_info info; + HRESULT hr;
info.unregister = TRUE; info.modules_size = 0; @@ -1162,8 +1170,14 @@ BOOL WINAPI SetupInstallFromInfSectionW( HWND owner, HINF hinf, PCWSTR section, } else info.callback = NULL;
+ hr = CoInitialize(NULL); + ret = iterate_section_fields( hinf, section, UnregisterDlls, register_dlls_callback, &info ); for (i = 0; i < info.modules_count; i++) FreeLibrary( info.modules[i] ); + + if (SUCCEEDED(hr)) + CoUninitialize(); + HeapFree( GetProcessHeap(), 0, info.modules ); if (!ret) return FALSE; } diff --git a/dlls/setupapi/tests/install.c b/dlls/setupapi/tests/install.c index b918bb21f60..8a2f9eec351 100644 --- a/dlls/setupapi/tests/install.c +++ b/dlls/setupapi/tests/install.c @@ -2092,7 +2092,7 @@ static void test_register_dlls(void) ok(ret, "Failed to install, error %#x.\n", GetLastError());
l = RegOpenKeyA(HKEY_CURRENT_USER, "winetest_setupapi_selfreg", &key); - todo_wine ok(!l, "Got error %u.\n", l); + ok(!l, "Got error %u.\n", l); RegCloseKey(key);
ret = SetupInstallFromInfSectionA(NULL, hinf, "DefaultInstall", SPINST_UNREGSVR,
From: Zebediah Figura zfigura@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/devenum/devenum_main.c | 6 ------ 1 file changed, 6 deletions(-)
diff --git a/dlls/devenum/devenum_main.c b/dlls/devenum/devenum_main.c index 51cdd3a6fba..d8b0f2cf692 100644 --- a/dlls/devenum/devenum_main.c +++ b/dlls/devenum/devenum_main.c @@ -158,10 +158,6 @@ HRESULT WINAPI DllRegisterServer(void) if (FAILED(res)) return res;
-/*** ActiveMovieFilter Categories ***/ - - CoInitialize(NULL); - res = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC, &IID_IFilterMapper2, &mapvptr); if (SUCCEEDED(res)) @@ -191,8 +187,6 @@ HRESULT WINAPI DllRegisterServer(void) IFilterMapper2_Release(pMapper); }
- CoUninitialize(); - return res; }
From: Zebediah Figura zfigura@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/quartz/regsvr.c | 4 ---- 1 file changed, 4 deletions(-)
diff --git a/dlls/quartz/regsvr.c b/dlls/quartz/regsvr.c index 015862f0352..ff5db662f04 100644 --- a/dlls/quartz/regsvr.c +++ b/dlls/quartz/regsvr.c @@ -158,8 +158,6 @@ static HRESULT unregister_filters(struct regsvr_filter const *list) HRESULT hr; IFilterMapper2* pFM2;
- CoInitialize(NULL); - hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER, &IID_IFilterMapper2, (LPVOID*)&pFM2);
if (SUCCEEDED(hr)) { @@ -168,8 +166,6 @@ static HRESULT unregister_filters(struct regsvr_filter const *list) IFilterMapper2_Release(pFM2); }
- CoUninitialize(); - return hr; }
From: Zebediah Figura zfigura@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/strmbase/dllfunc.c | 6 ------ 1 file changed, 6 deletions(-)
diff --git a/dlls/strmbase/dllfunc.c b/dlls/strmbase/dllfunc.c index 842bee6121d..ca5557ec249 100644 --- a/dlls/strmbase/dllfunc.c +++ b/dlls/strmbase/dllfunc.c @@ -149,8 +149,6 @@ HRESULT WINAPI AMovieDllRegisterServer2(BOOL bRegister) if (bRegister) hr = SetupRegisterAllClasses(g_Templates, g_cTemplates, szFileName, TRUE );
- CoInitialize(NULL); - TRACE("Getting IFilterMapper2\r\n"); hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER, &IID_IFilterMapper2, (void **)&pIFM2); @@ -162,10 +160,6 @@ HRESULT WINAPI AMovieDllRegisterServer2(BOOL bRegister) if (pIFM2) IFilterMapper2_Release(pIFM2);
- /* and clear up */ - CoFreeUnusedLibraries(); - CoUninitialize(); - /* if unregistering, unregister all OLE servers */ if (SUCCEEDED(hr) && !bRegister) hr = SetupRegisterAllClasses(g_Templates, g_cTemplates, szFileName, FALSE);