bits[3/3]: Added support for bits object registration and creation
Roy Shea
roy at cs.hmc.edu
Wed Sep 26 17:34:35 CDT 2007
Big patch adding support for registry registration and very basic
object creation.
-------------- next part --------------
diff --git a/dlls/bits/Makefile.in b/dlls/bits/Makefile.in
index 7645c5a..aab13c8 100644
--- a/dlls/bits/Makefile.in
+++ b/dlls/bits/Makefile.in
@@ -3,12 +3,15 @@ TOPOBJDIR = ../..
SRCDIR = @srcdir@
VPATH = @srcdir@
MODULE = bits.dll
-IMPORTLIB = libbits.$(IMPLIBEXT)
-IMPORTS = kernel32
+IMPORTS = ole32 user32 advapi32 kernel32
EXTRALIBS = -luuid
C_SRCS = \
- bits_main.c
+ bits_main.c \
+ factory.c \
+ iunknown.c \
+ bcm.c \
+ regsvr.c
IDL_I_SRCS = bits_local.idl
#RC_SRCS = version.rc
diff --git a/dlls/bits/bcm.c b/dlls/bits/bcm.c
new file mode 100644
index 0000000..ffe924f
--- /dev/null
+++ b/dlls/bits/bcm.c
@@ -0,0 +1,115 @@
+/*
+ * Bits core functions
+ *
+ * Copyright 2007 Google (Roy Shea)
+ *
+ * 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
+ */
+
+#include "bits_private.h"
+
+#include "wine/debug.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(bits);
+
+/*** IUnknown methods ***/
+static HRESULT WINAPI BITS_IBackgroundCopyManager_QueryInterface(
+ IBackgroundCopyManager* iface,
+ REFIID riid,
+ void **ppvObject)
+{
+ ICOM_THIS_MULTI(BitsMgrImpl, bcmVtbl, iface);
+ TRACE("\n\tIID:\t%s\n",debugstr_guid(riid));
+
+ if (This == NULL || ppvObject == NULL) return E_POINTER;
+
+ return IUnknown_QueryInterface((LPUNKNOWN)&This->unkVtbl, riid, ppvObject);
+}
+
+static ULONG WINAPI BITS_IBackgroundCopyManager_AddRef(
+ IBackgroundCopyManager* iface)
+{
+ ICOM_THIS_MULTI(BitsMgrImpl, bcmVtbl, iface);
+ TRACE("\n");
+
+ if (This == NULL) return E_POINTER;
+
+ return IUnknown_AddRef((LPUNKNOWN)&This->unkVtbl);
+}
+
+static ULONG WINAPI BITS_IBackgroundCopyManager_Release(
+ IBackgroundCopyManager* iface)
+{
+ ICOM_THIS_MULTI(BitsMgrImpl, bcmVtbl, iface);
+ TRACE("\n");
+
+ if (This == NULL) return E_POINTER;
+
+ return IUnknown_Release((LPUNKNOWN)&This->unkVtbl);
+}
+
+/*** IBackgroundCopyManager methods ***/
+static HRESULT WINAPI BITS_IBackgroundCopyManager_CreateJob(
+ IBackgroundCopyManager* This,
+ LPCWSTR DisplayName,
+ BG_JOB_TYPE Type,
+ GUID *pJobId,
+ IBackgroundCopyJob **ppJob)
+{
+ FIXME("Not implemented\n");
+ return E_NOTIMPL;
+}
+
+static HRESULT WINAPI BITS_IBackgroundCopyManager_GetJob(
+ IBackgroundCopyManager* This,
+ REFGUID jobID,
+ IBackgroundCopyJob **ppJob)
+{
+ FIXME("Not implemented\n");
+ return E_NOTIMPL;
+}
+
+static HRESULT WINAPI BITS_IBackgroundCopyManager_EnumJobs(
+ IBackgroundCopyManager* This,
+ DWORD dwFlags,
+ IEnumBackgroundCopyJobs **ppEnum)
+{
+ FIXME("Not implemented\n");
+ return E_NOTIMPL;
+}
+
+static HRESULT WINAPI BITS_IBackgroundCopyManager_GetErrorDescription(
+ IBackgroundCopyManager* This,
+ HRESULT hResult,
+ DWORD LanguageId,
+ LPWSTR *pErrorDescription)
+{
+ FIXME("Not implemented\n");
+ return E_NOTIMPL;
+}
+
+
+const IBackgroundCopyManagerVtbl BITS_IBackgroundCopyManager_Vtbl =
+{
+ BITS_IBackgroundCopyManager_QueryInterface,
+ BITS_IBackgroundCopyManager_AddRef,
+ BITS_IBackgroundCopyManager_Release,
+ BITS_IBackgroundCopyManager_CreateJob,
+ BITS_IBackgroundCopyManager_GetJob,
+ BITS_IBackgroundCopyManager_EnumJobs,
+ BITS_IBackgroundCopyManager_GetErrorDescription
+};
+
+
diff --git a/dlls/bits/bits.spec b/dlls/bits/bits.spec
index c5fc87a..b16365d 100644
--- a/dlls/bits/bits.spec
+++ b/dlls/bits/bits.spec
@@ -1,4 +1,4 @@
-@ stub DllCanUnloadNow
-@ stub DllGetClassObject
-@ stub DllRegisterServer
-@ stub DllUnregisterServer
+@ stdcall -private DllCanUnloadNow()
+@ stdcall -private DllGetClassObject(ptr ptr ptr)
+@ stdcall -private DllRegisterServer()
+@ stdcall -private DllUnregisterServer()
diff --git a/dlls/bits/bits_main.c b/dlls/bits/bits_main.c
index 7d231c4..ce3de7b 100644
--- a/dlls/bits/bits_main.c
+++ b/dlls/bits/bits_main.c
@@ -21,29 +21,47 @@
#include <stdarg.h>
-#include "windef.h"
-#include "winbase.h"
#include "wine/debug.h"
-#include "objbase.h"
-#include "bits.h"
+#include "bits_private.h"
WINE_DEFAULT_DEBUG_CHANNEL(bits);
+LONG dll_ref = 0;
+
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
TRACE("(%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
switch (fdwReason)
{
- case DLL_WINE_PREATTACH:
- return FALSE; /* prefer native version */
- case DLL_PROCESS_ATTACH:
- DisableThreadLibraryCalls(hinstDLL);
- break;
- case DLL_PROCESS_DETACH:
- break;
+ case DLL_WINE_PREATTACH:
+ return FALSE; /* prefer native version */
+ case DLL_PROCESS_ATTACH:
+ DisableThreadLibraryCalls(hinstDLL);
+ break;
+ case DLL_PROCESS_DETACH:
+ break;
}
-
+
return TRUE;
}
+
+
+HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
+{
+ *ppv = NULL;
+ if (IsEqualGUID(rclsid, &CLSID_BackgroundCopyManager)) {
+ return IClassFactory_QueryInterface((LPCLASSFACTORY)&BITS_ClassFactory, iid, ppv);
+ }
+ FIXME("\n\tCLSID:\t%s,\n\tIID:\t%s\n",debugstr_guid(rclsid),debugstr_guid(iid));
+ return CLASS_E_CLASSNOTAVAILABLE;
+}
+
+HRESULT WINAPI DllCanUnloadNow(void)
+{
+ return dll_ref != 0 ? S_FALSE : S_OK;
+}
+
+
+/* NOTE: DllRegisterServer and DllUnregisterServer are in regsvr.c */
diff --git a/dlls/bits/bits_private.h b/dlls/bits/bits_private.h
new file mode 100644
index 0000000..13e29a6
--- /dev/null
+++ b/dlls/bits/bits_private.h
@@ -0,0 +1,67 @@
+/*
+ * Register and unregister bits.dll functions
+ *
+ * Copyright 2007 Google (Roy Shea)
+ * Based on dlls/comcat/comcat_private.c by John K. Hohm
+ *
+ * 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
+ */
+
+#include <stdarg.h>
+
+#define COBJMACROS
+
+#include "windef.h"
+#include "winbase.h"
+#include "winuser.h"
+#include "winreg.h"
+#include "winerror.h"
+
+#include "ole2.h"
+#include "bits.h"
+#include "wine/unicode.h"
+
+#define ICOM_THIS_MULTI(impl,field,iface) impl* const This=(impl*)((char*)(iface) - offsetof(impl,field))
+
+/*
+ * Dll lifetime tracking declaration for bits.dll
+ */
+extern LONG dll_ref;
+
+/*
+ * ClassFactory declaration for bits.dll
+ */
+typedef struct
+{
+ const IClassFactoryVtbl *lpVtbl;
+ LONG ref;
+} ClassFactoryImpl;
+
+extern ClassFactoryImpl BITS_ClassFactory;
+
+/*
+ * Bits instance
+ */
+typedef struct
+{
+ const IUnknownVtbl *unkVtbl;
+ const IBackgroundCopyManagerVtbl *bcmVtbl;
+ LONG ref;
+} BitsMgrImpl;
+
+extern BitsMgrImpl BITS_BitsMgr;
+extern const IBackgroundCopyManagerVtbl BITS_IBackgroundCopyManager_Vtbl;
+
+
diff --git a/dlls/bits/factory.c b/dlls/bits/factory.c
new file mode 100644
index 0000000..8643112
--- /dev/null
+++ b/dlls/bits/factory.c
@@ -0,0 +1,151 @@
+/*
+ * Register and unregister bits.dll functions
+ *
+ * Copyright 2007 Google (Roy Shea)
+ * Based on dlls/comcat/factory.c by John K. Hohm
+ *
+ * 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
+ */
+
+#include "bits_private.h"
+
+#include "wine/debug.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(bits);
+
+static ULONG WINAPI BITS_IClassFactory_AddRef(LPCLASSFACTORY iface);
+
+/*
+ * BITS_IClassFactory_QueryInterface (also IUnknown)
+ */
+static HRESULT WINAPI BITS_IClassFactory_QueryInterface(
+ LPCLASSFACTORY iface,
+ REFIID riid,
+ LPVOID *ppvObj)
+{
+ ClassFactoryImpl *This = (ClassFactoryImpl *)iface;
+ TRACE("\n\tIID:\t%s\n",debugstr_guid(riid));
+
+ if (This == NULL || ppvObj == NULL) return E_POINTER;
+
+ if (IsEqualGUID(riid, &IID_IUnknown) ||
+ IsEqualGUID(riid, &IID_IClassFactory))
+ {
+ *ppvObj = (LPVOID)iface;
+ BITS_IClassFactory_AddRef(iface);
+ return S_OK;
+ }
+
+ return E_NOINTERFACE;
+}
+
+/*
+ * BITS_IClassFactory_AddRef (also IUnknown)
+ */
+static ULONG WINAPI BITS_IClassFactory_AddRef(LPCLASSFACTORY iface)
+{
+ ClassFactoryImpl *This = (ClassFactoryImpl *)iface;
+ ULONG ref;
+
+ TRACE("\n");
+
+ if (This == NULL) return E_POINTER;
+
+ ref = InterlockedIncrement(&This->ref);
+ if (ref == 1) {
+ InterlockedIncrement(&dll_ref);
+ }
+ return ref;
+}
+
+/*
+ * BITS_IClassFactory_Release (also IUnknown)
+ */
+static ULONG WINAPI BITS_IClassFactory_Release(LPCLASSFACTORY iface)
+{
+ ClassFactoryImpl *This = (ClassFactoryImpl *)iface;
+ ULONG ref;
+
+ TRACE("\n");
+
+ if (This == NULL) return E_POINTER;
+
+ ref = InterlockedDecrement(&This->ref);
+ if (ref == 0) {
+ InterlockedDecrement(&dll_ref);
+ }
+ return ref;
+}
+
+
+/*
+ * BITS_IClassFactory_CreateInstance
+ */
+static HRESULT WINAPI BITS_IClassFactory_CreateInstance(
+ LPCLASSFACTORY iface,
+ LPUNKNOWN pUnkOuter,
+ REFIID riid,
+ LPVOID *ppvObj)
+{
+ ClassFactoryImpl *This = (ClassFactoryImpl *)iface;
+ HRESULT res;
+ TRACE("\n\tIID:\t%s\n",debugstr_guid(riid));
+
+ if (This == NULL || ppvObj == NULL) return E_POINTER;
+
+ /* Don't support aggregation (Windows doesn't) */
+ if (pUnkOuter != NULL) return CLASS_E_NOAGGREGATION;
+
+ res = IUnknown_QueryInterface((LPUNKNOWN)&BITS_BitsMgr, riid, ppvObj);
+ if (SUCCEEDED(res)) {
+ return res;
+ }
+
+ return CLASS_E_CLASSNOTAVAILABLE;
+}
+
+/*
+ * BITS_IClassFactory_LockServer
+ */
+static HRESULT WINAPI BITS_IClassFactory_LockServer(
+ LPCLASSFACTORY iface,
+ BOOL fLock)
+{
+ TRACE("\n");
+
+ if (fLock != FALSE) {
+ IClassFactory_AddRef(iface);
+ } else {
+ IClassFactory_Release(iface);
+ }
+ return S_OK;
+}
+
+/*
+ * IClassFactory_Vtbl
+ */
+static const IClassFactoryVtbl IClassFactory_Vtbl =
+{
+ BITS_IClassFactory_QueryInterface,
+ BITS_IClassFactory_AddRef,
+ BITS_IClassFactory_Release,
+ BITS_IClassFactory_CreateInstance,
+ BITS_IClassFactory_LockServer
+};
+
+/*
+ * static ClassFactory instance
+ */
+ClassFactoryImpl BITS_ClassFactory = { &IClassFactory_Vtbl, 0 };
diff --git a/dlls/bits/iunknown.c b/dlls/bits/iunknown.c
new file mode 100644
index 0000000..69d5a6c
--- /dev/null
+++ b/dlls/bits/iunknown.c
@@ -0,0 +1,117 @@
+/*
+ * Register and unregister bits.dll functions
+ *
+ * Copyright 2007 Google (Roy Shea)
+ * Based on dlls/comcat/manager.c by John K. Hohm
+ *
+ * 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
+ */
+
+#include "bits_private.h"
+
+#include "wine/debug.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(ole);
+
+static ULONG WINAPI BITS_IUnknown_AddRef(LPUNKNOWN iface);
+
+/*
+ * BITS_IUnknown_QueryInterface
+ */
+static HRESULT WINAPI BITS_IUnknown_QueryInterface(
+ LPUNKNOWN iface,
+ REFIID riid,
+ LPVOID *ppvObj)
+{
+ ICOM_THIS_MULTI(BitsMgrImpl, unkVtbl, iface);
+ TRACE("\n\tIID:\t%s\n",debugstr_guid(riid));
+
+ if (This == NULL || ppvObj == NULL) return E_POINTER;
+
+ if (IsEqualGUID(riid, &IID_IUnknown)) {
+ *ppvObj = &This->unkVtbl;
+ BITS_IUnknown_AddRef(iface);
+ return S_OK;
+ }
+
+ if (IsEqualGUID(riid, &IID_IBackgroundCopyManager)) {
+ *ppvObj = &This->bcmVtbl;
+ BITS_IUnknown_AddRef(iface);
+ return S_OK;
+ }
+
+ return E_NOINTERFACE;
+}
+
+/*
+ * BITS_IUnknown_AddRef
+ */
+static ULONG WINAPI BITS_IUnknown_AddRef(LPUNKNOWN iface)
+{
+ ICOM_THIS_MULTI(BitsMgrImpl, unkVtbl, iface);
+ ULONG ref;
+
+ TRACE("\n");
+
+ if (This == NULL) return E_POINTER;
+
+ ref = InterlockedIncrement(&This->ref);
+ if (ref == 1) {
+ InterlockedIncrement(&dll_ref);
+ }
+ return ref;
+}
+
+/*
+ * BITS_IUnknown_Release
+ */
+static ULONG WINAPI BITS_IUnknown_Release(LPUNKNOWN iface)
+{
+ ICOM_THIS_MULTI(BitsMgrImpl, unkVtbl, iface);
+ ULONG ref;
+
+ TRACE("\n");
+
+ if (This == NULL) return E_POINTER;
+
+ ref = InterlockedDecrement(&This->ref);
+ if (ref == 0) {
+ InterlockedDecrement(&dll_ref);
+ }
+ return ref;
+}
+
+
+/*
+ * BITS_IUnknown_Vtbl
+ */
+static const IUnknownVtbl BITS_IUnknown_Vtbl =
+{
+ BITS_IUnknown_QueryInterface,
+ BITS_IUnknown_AddRef,
+ BITS_IUnknown_Release
+};
+
+/*
+ * static Bits instance
+ */
+BitsMgrImpl BITS_BitsMgr =
+{
+ &BITS_IUnknown_Vtbl,
+ &BITS_IBackgroundCopyManager_Vtbl,
+ 0
+};
+
+
diff --git a/dlls/bits/regsvr.c b/dlls/bits/regsvr.c
new file mode 100644
index 0000000..1738538
--- /dev/null
+++ b/dlls/bits/regsvr.c
@@ -0,0 +1,488 @@
+/*
+ * Register and unregister bits.dll functions
+ *
+ * Copyright 2007 Google (Roy Shea)
+ * Based on dlls/comcat/regsvr.c by John K. Hohm
+ *
+ * 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 "wine/debug.h"
+#include "windef.h"
+#include "winbase.h"
+#include "winuser.h"
+#include "winreg.h"
+#include "winerror.h"
+
+#include "ole2.h"
+#include "bits.h"
+#include "wine/unicode.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(ole);
+
+/*
+ * Interface for self-registering
+ */
+struct regsvr_interface
+{
+ IID const *iid; /* NULL for end of list */
+ LPCSTR name; /* can be NULL to omit */
+ IID const *base_iid; /* can be NULL to omit */
+ int num_methods; /* can be <0 to omit */
+ CLSID const *ps_clsid; /* can be NULL to omit */
+ CLSID const *ps_clsid32; /* can be NULL to omit */
+};
+
+static HRESULT register_interfaces(struct regsvr_interface const *list);
+static HRESULT unregister_interfaces(struct regsvr_interface const *list);
+
+struct regsvr_coclass
+{
+ CLSID const *clsid; /* NULL for end of list */
+ LPCSTR name; /* can be NULL to omit */
+ LPCSTR ips; /* can be NULL to omit */
+ LPCSTR ips32; /* can be NULL to omit */
+ LPCSTR ips32_tmodel; /* can be NULL to omit */
+};
+
+static HRESULT register_coclasses(struct regsvr_coclass const *list);
+static HRESULT unregister_coclasses(struct regsvr_coclass const *list);
+
+/*
+ * Static string constants
+ */
+static WCHAR const interface_keyname[10] = {
+ 'I', 'n', 't', 'e', 'r', 'f', 'a', 'c', 'e', 0 };
+static WCHAR const base_ifa_keyname[14] = {
+ 'B', 'a', 's', 'e', 'I', 'n', 't', 'e', 'r', 'f', 'a', 'c',
+ 'e', 0 };
+static WCHAR const num_methods_keyname[11] = {
+ 'N', 'u', 'm', 'M', 'e', 't', 'h', 'o', 'd', 's', 0 };
+static WCHAR const ps_clsid_keyname[15] = {
+ 'P', 'r', 'o', 'x', 'y', 'S', 't', 'u', 'b', 'C', 'l', 's',
+ 'i', 'd', 0 };
+static WCHAR const ps_clsid32_keyname[17] = {
+ 'P', 'r', 'o', 'x', 'y', 'S', 't', 'u', 'b', 'C', 'l', 's',
+ 'i', 'd', '3', '2', 0 };
+static WCHAR const clsid_keyname[6] = {
+ 'C', 'L', 'S', 'I', 'D', 0 };
+static WCHAR const ips_keyname[13] = {
+ 'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r',
+ 0 };
+static WCHAR const ips32_keyname[15] = {
+ 'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r',
+ '3', '2', 0 };
+static char const tmodel_valuename[] = "ThreadingModel";
+
+/*
+ * Static helper functions
+ */
+static LONG register_key_guid(HKEY base, WCHAR const *name, GUID const *guid);
+static LONG register_key_defvalueW(HKEY base, WCHAR const *name,
+ WCHAR const *value);
+static LONG register_key_defvalueA(HKEY base, WCHAR const *name,
+ char const *value);
+static LONG recursive_delete_key(HKEY key);
+
+
+/*
+ * Register_interfaces
+ */
+static HRESULT register_interfaces(struct regsvr_interface const *list)
+{
+ LONG res = ERROR_SUCCESS;
+ HKEY interface_key;
+
+ res = RegCreateKeyExW(HKEY_CLASSES_ROOT, interface_keyname, 0, NULL, 0,
+ KEY_READ | KEY_WRITE, NULL, &interface_key, NULL);
+ if (res != ERROR_SUCCESS) goto error_return;
+
+ for (; res == ERROR_SUCCESS && list->iid; ++list) {
+ WCHAR buf[39];
+ HKEY iid_key;
+
+ StringFromGUID2(list->iid, buf, 39);
+ res = RegCreateKeyExW(interface_key, buf, 0, NULL, 0,
+ KEY_READ | KEY_WRITE, NULL, &iid_key, NULL);
+ if (res != ERROR_SUCCESS) goto error_close_interface_key;
+
+ if (list->name) {
+ res = RegSetValueExA(iid_key, NULL, 0, REG_SZ,
+ (CONST BYTE*)(list->name),
+ strlen(list->name) + 1);
+ if (res != ERROR_SUCCESS) goto error_close_iid_key;
+ }
+
+ if (list->base_iid) {
+ res = register_key_guid(iid_key, base_ifa_keyname, list->base_iid);
+ if (res != ERROR_SUCCESS) goto error_close_iid_key;
+ }
+
+ if (0 <= list->num_methods) {
+ static WCHAR const fmt[3] = { '%', 'd', 0 };
+ HKEY key;
+
+ res = RegCreateKeyExW(iid_key, num_methods_keyname, 0, NULL, 0,
+ KEY_READ | KEY_WRITE, NULL, &key, NULL);
+ if (res != ERROR_SUCCESS) goto error_close_iid_key;
+
+ wsprintfW(buf, fmt, list->num_methods);
+ res = RegSetValueExW(key, NULL, 0, REG_SZ,
+ (CONST BYTE*)buf,
+ (lstrlenW(buf) + 1) * sizeof(WCHAR));
+ RegCloseKey(key);
+
+ if (res != ERROR_SUCCESS) goto error_close_iid_key;
+ }
+
+ if (list->ps_clsid) {
+ res = register_key_guid(iid_key, ps_clsid_keyname, list->ps_clsid);
+ if (res != ERROR_SUCCESS) goto error_close_iid_key;
+ }
+
+ if (list->ps_clsid32) {
+ res = register_key_guid(iid_key, ps_clsid32_keyname, list->ps_clsid32);
+ if (res != ERROR_SUCCESS) goto error_close_iid_key;
+ }
+
+error_close_iid_key:
+ RegCloseKey(iid_key);
+ }
+
+error_close_interface_key:
+ RegCloseKey(interface_key);
+error_return:
+ return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
+}
+
+/*
+ * unregister_interfaces
+ */
+static HRESULT unregister_interfaces(struct regsvr_interface const *list)
+{
+ LONG res = ERROR_SUCCESS;
+ HKEY interface_key;
+
+ res = RegOpenKeyExW(HKEY_CLASSES_ROOT, interface_keyname, 0,
+ KEY_READ | KEY_WRITE, &interface_key);
+ if (res == ERROR_FILE_NOT_FOUND) return S_OK;
+ if (res != ERROR_SUCCESS) goto error_return;
+
+ for (; res == ERROR_SUCCESS && list->iid; ++list) {
+ WCHAR buf[39];
+ HKEY iid_key;
+
+ StringFromGUID2(list->iid, buf, 39);
+ res = RegOpenKeyExW(interface_key, buf, 0,
+ KEY_READ | KEY_WRITE, &iid_key);
+ if (res == ERROR_FILE_NOT_FOUND) {
+ res = ERROR_SUCCESS;
+ continue;
+ }
+ if (res != ERROR_SUCCESS) goto error_close_interface_key;
+ res = recursive_delete_key(iid_key);
+ RegCloseKey(iid_key);
+ if (res != ERROR_SUCCESS) goto error_close_interface_key;
+ }
+
+error_close_interface_key:
+ RegCloseKey(interface_key);
+error_return:
+ return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
+}
+
+/*
+ * egister_coclasses
+ */
+static HRESULT register_coclasses(struct regsvr_coclass const *list)
+{
+ LONG res = ERROR_SUCCESS;
+ HKEY coclass_key;
+
+ res = RegCreateKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0, NULL, 0,
+ KEY_READ | KEY_WRITE, NULL, &coclass_key, NULL);
+ if (res != ERROR_SUCCESS) goto error_return;
+
+ for (; res == ERROR_SUCCESS && list->clsid; ++list) {
+ WCHAR buf[39];
+ HKEY clsid_key;
+
+ StringFromGUID2(list->clsid, buf, 39);
+ res = RegCreateKeyExW(coclass_key, buf, 0, NULL, 0,
+ KEY_READ | KEY_WRITE, NULL, &clsid_key, NULL);
+ if (res != ERROR_SUCCESS) goto error_close_coclass_key;
+
+ if (list->name) {
+ res = RegSetValueExA(clsid_key, NULL, 0, REG_SZ,
+ (CONST BYTE*)(list->name),
+ strlen(list->name) + 1);
+ if (res != ERROR_SUCCESS) goto error_close_clsid_key;
+ }
+
+ if (list->ips) {
+ res = register_key_defvalueA(clsid_key, ips_keyname, list->ips);
+ if (res != ERROR_SUCCESS) goto error_close_clsid_key;
+ }
+
+ if (list->ips32) {
+ HKEY ips32_key;
+
+ res = RegCreateKeyExW(clsid_key, ips32_keyname, 0, NULL, 0,
+ KEY_READ | KEY_WRITE, NULL,
+ &ips32_key, NULL);
+ if (res != ERROR_SUCCESS) goto error_close_clsid_key;
+
+ res = RegSetValueExA(ips32_key, NULL, 0, REG_SZ,
+ (CONST BYTE*)list->ips32,
+ lstrlenA(list->ips32) + 1);
+ if (res == ERROR_SUCCESS && list->ips32_tmodel)
+ res = RegSetValueExA(ips32_key, tmodel_valuename, 0, REG_SZ,
+ (CONST BYTE*)list->ips32_tmodel,
+ strlen(list->ips32_tmodel) + 1);
+ RegCloseKey(ips32_key);
+ if (res != ERROR_SUCCESS) goto error_close_clsid_key;
+ }
+
+error_close_clsid_key:
+ RegCloseKey(clsid_key);
+ }
+
+error_close_coclass_key:
+ RegCloseKey(coclass_key);
+error_return:
+ return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
+}
+
+/*
+ * unregister_coclasses
+ */
+static HRESULT unregister_coclasses(struct regsvr_coclass const *list)
+{
+ LONG res = ERROR_SUCCESS;
+ HKEY coclass_key;
+
+ res = RegOpenKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0,
+ KEY_READ | KEY_WRITE, &coclass_key);
+ if (res == ERROR_FILE_NOT_FOUND) return S_OK;
+ if (res != ERROR_SUCCESS) goto error_return;
+
+ for (; res == ERROR_SUCCESS && list->clsid; ++list) {
+ WCHAR buf[39];
+ HKEY clsid_key;
+
+ StringFromGUID2(list->clsid, buf, 39);
+ res = RegOpenKeyExW(coclass_key, buf, 0,
+ KEY_READ | KEY_WRITE, &clsid_key);
+ if (res == ERROR_FILE_NOT_FOUND) {
+ res = ERROR_SUCCESS;
+ continue;
+ }
+ if (res != ERROR_SUCCESS) goto error_close_coclass_key;
+ res = recursive_delete_key(clsid_key);
+ RegCloseKey(clsid_key);
+ if (res != ERROR_SUCCESS) goto error_close_coclass_key;
+ }
+
+error_close_coclass_key:
+ RegCloseKey(coclass_key);
+error_return:
+ return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
+}
+
+/*
+ * regsvr_key_guid
+ */
+static LONG register_key_guid(HKEY base, WCHAR const *name, GUID const *guid)
+{
+ WCHAR buf[39];
+
+ StringFromGUID2(guid, buf, 39);
+ return register_key_defvalueW(base, name, buf);
+}
+
+/*
+ * regsvr_key_defvalueW
+ */
+static LONG register_key_defvalueW(
+ HKEY base,
+ WCHAR const *name,
+ WCHAR const *value)
+{
+ LONG res;
+ HKEY key;
+
+ res = RegCreateKeyExW(base, name, 0, NULL, 0,
+ KEY_READ | KEY_WRITE, NULL, &key, NULL);
+ if (res != ERROR_SUCCESS) return res;
+ res = RegSetValueExW(key, NULL, 0, REG_SZ, (CONST BYTE*)value,
+ (lstrlenW(value) + 1) * sizeof(WCHAR));
+ RegCloseKey(key);
+ return res;
+}
+
+/*
+ * regsvr_key_defvalueA
+ */
+static LONG register_key_defvalueA(
+ HKEY base,
+ WCHAR const *name,
+ char const *value)
+{
+ LONG res;
+ HKEY key;
+
+ res = RegCreateKeyExW(base, name, 0, NULL, 0,
+ KEY_READ | KEY_WRITE, NULL, &key, NULL);
+ if (res != ERROR_SUCCESS) return res;
+ res = RegSetValueExA(key, NULL, 0, REG_SZ, (CONST BYTE*)value,
+ lstrlenA(value) + 1);
+ RegCloseKey(key);
+ return res;
+}
+
+/*
+ * recursive_delete_key
+ */
+static LONG recursive_delete_key(HKEY key)
+{
+ LONG res;
+ WCHAR subkey_name[MAX_PATH];
+ DWORD cName;
+ HKEY subkey;
+
+ for (;;) {
+ cName = sizeof(subkey_name) / sizeof(WCHAR);
+ res = RegEnumKeyExW(key, 0, subkey_name, &cName,
+ NULL, NULL, NULL, NULL);
+ if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) {
+ res = ERROR_SUCCESS; /* presumably we're done enumerating */
+ break;
+ }
+ res = RegOpenKeyExW(key, subkey_name, 0,
+ KEY_READ | KEY_WRITE, &subkey);
+ if (res == ERROR_FILE_NOT_FOUND) continue;
+ if (res != ERROR_SUCCESS) break;
+
+ res = recursive_delete_key(subkey);
+ RegCloseKey(subkey);
+ if (res != ERROR_SUCCESS) break;
+ }
+
+ if (res == ERROR_SUCCESS) res = RegDeleteKeyW(key, 0);
+ return res;
+}
+
+/*
+ * Coclass list
+ */
+static struct regsvr_coclass const coclass_list[] = {
+ { &CLSID_BackgroundCopyManager,
+ "Background Intelligent Transfer Service",
+ NULL,
+ "bits.dll",
+ "Both"
+ },
+ { NULL } /* list terminator */
+};
+
+/*
+ * Interface list
+ */
+static struct regsvr_interface const interface_list[] = {
+ { &IID_IBackgroundCopyFile,
+ "IBackgroundCopyFile",
+ NULL,
+ 3,
+ NULL,
+ NULL
+ },
+ { &IID_IEnumBackgroundCopyFiles,
+ "IEnumBackgroundCopyFiles",
+ NULL,
+ 5,
+ NULL,
+ NULL
+ },
+ { &IID_IBackgroundCopyError,
+ "IBackgroundCopyError",
+ NULL,
+ 5,
+ NULL,
+ NULL
+ },
+ { &IID_IBackgroundCopyJob,
+ "IBackgroundCopyJob",
+ NULL,
+ 32,
+ NULL,
+ NULL
+ },
+ { &IID_IEnumBackgroundCopyJobs,
+ "IEnumBackgroundCopyJobs",
+ NULL,
+ 5,
+ NULL,
+ NULL
+ },
+ { &IID_IBackgroundCopyCallback,
+ "IBackgroundCopyCallback",
+ NULL,
+ 3,
+ NULL,
+ NULL
+ },
+ { &IID_IBackgroundCopyManager,
+ "IBackgroundCopyManager",
+ NULL,
+ 4,
+ NULL,
+ NULL
+ },
+ { NULL } /* list terminator */
+};
+
+/*
+ * DllRegisterServer (BITS.@)
+ */
+HRESULT WINAPI DllRegisterServer(void)
+{
+ HRESULT hr;
+
+ TRACE("\n");
+
+ hr = register_coclasses(coclass_list);
+ if (SUCCEEDED(hr))
+ hr = register_interfaces(interface_list);
+ return hr;
+}
+
+/*
+ * DllUnregisterServer (BITS.@)
+ */
+HRESULT WINAPI DllUnregisterServer(void)
+{
+ HRESULT hr;
+
+ TRACE("\n");
+
+ hr = unregister_coclasses(coclass_list);
+ if (SUCCEEDED(hr))
+ hr = unregister_interfaces(interface_list);
+ return hr;
+}
+
+
diff --git a/dlls/bits/tests/Makefile.in b/dlls/bits/tests/Makefile.in
new file mode 100644
index 0000000..9599c37
--- /dev/null
+++ b/dlls/bits/tests/Makefile.in
@@ -0,0 +1,17 @@
+TOPSRCDIR = @top_srcdir@
+TOPOBJDIR = ../../..
+SRCDIR = @srcdir@
+VPATH = @srcdir@
+TESTDLL = bits.dll
+IMPORTS = ole32 kernel32
+MODCFLAGS = @BUILTINFLAG@
+EXTRAINCL = -I$(SRCDIR)/..
+
+CTESTS = \
+ bits_test.c
+
+IDL_I_SRCS = ../bits_local.idl
+
+ at MAKE_TEST_RULES@
+
+ at DEPENDENCIES@ # everything below this line is overwritten by make depend
diff --git a/dlls/bits/tests/bits_test.c b/dlls/bits/tests/bits_test.c
new file mode 100644
index 0000000..89b947e
--- /dev/null
+++ b/dlls/bits/tests/bits_test.c
@@ -0,0 +1,52 @@
+/*
+ * Unit test suite for bits functions
+ *
+ * Copyright 2007 Google (Roy Shea)
+ *
+ * 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
+ */
+
+#include <stdio.h>
+
+#define COBJMACROS
+
+#include "wine/test.h"
+#include "bits.h"
+
+static void test_CreateInstance(void)
+{
+ HRESULT hres;
+ IBackgroundCopyManager* manager = NULL;
+
+ /* Creating bits instance */
+ hres = CoCreateInstance(&CLSID_BackgroundCopyManager, NULL,
+ CLSCTX_ALL, &IID_IBackgroundCopyManager,
+ (void **) &manager);
+
+ ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
+ if(hres != S_OK) {
+ skip("Unable to create bits instance.\n");
+ return;
+ }
+
+}
+
+
+START_TEST(bits_test)
+{
+ CoInitialize(NULL);
+ test_CreateInstance();
+ CoUninitialize();
+}
More information about the wine-patches
mailing list