mshtml: Added nsINetUtil interface to nsIOService.
[wine/winequartzdrv.git] / dlls / qmgr / qmgr_main.c
blob0af200719dc3eb1bf6478e57c7468b3cf55b3d58
1 /*
2 * Main DLL interface to Queue Manager (BITS)
4 * Background Intelligent Transfer Service (BITS) interface. Dll is named
5 * qmgr for backwards compatibility with early versions of BITS.
7 * Copyright 2007 Google (Roy Shea)
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include <stdio.h>
26 #include "objbase.h"
27 #include "winuser.h"
28 #include "winreg.h"
29 #include "advpub.h"
30 #include "olectl.h"
31 #include "winsvc.h"
33 #include "bits.h"
34 #include "qmgr.h"
35 #include "initguid.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(qmgr);
41 /* Handle to the base address of this DLL */
42 static HINSTANCE hInst;
44 /* Other GUIDs used by this module */
45 DEFINE_GUID(CLSID_BackgroundCopyQMgr, 0x69AD4AEE, 0x51BE, 0x439b, 0xA9,0x2C, 0x86,0xAE,0x49,0x0E,0x8B,0x30);
47 /* Entry point for DLL */
48 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
50 TRACE("(%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
52 switch (fdwReason)
54 case DLL_WINE_PREATTACH:
55 return FALSE; /* prefer native version */
56 case DLL_PROCESS_ATTACH:
57 DisableThreadLibraryCalls(hinstDLL);
58 hInst = hinstDLL;
59 break;
60 case DLL_PROCESS_DETACH:
61 break;
64 return TRUE;
67 static HRESULT init_register_strtable(STRTABLEA *strtable)
69 #define CLSID_EXPANSION_ENTRY(id) { "CLSID_" #id, &CLSID_ ## id }
70 static const struct {
71 const char *name;
72 const CLSID *clsid;
73 } expns[] = {
74 CLSID_EXPANSION_ENTRY(BackgroundCopyQMgr),
75 CLSID_EXPANSION_ENTRY(BackgroundCopyManager)
77 #undef CLSID_EXPANSION_ENTRY
78 static STRENTRYA pse[sizeof expns / sizeof expns[0]];
79 int i;
81 strtable->cEntries = sizeof pse / sizeof pse[0];
82 strtable->pse = pse;
83 for (i = 0; i < strtable->cEntries; i++) {
84 static const char dummy_sample[] = "{12345678-1234-1234-1234-123456789012}";
85 const CLSID *clsid = expns[i].clsid;
86 pse[i].pszName = qmgr_strdup(expns[i].name);
87 pse[i].pszValue = HeapAlloc(GetProcessHeap(), 0, sizeof dummy_sample);
88 if (!pse[i].pszName || !pse[i].pszValue)
89 return E_OUTOFMEMORY;
90 sprintf(pse[i].pszValue, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
91 clsid->Data1, clsid->Data2, clsid->Data3, clsid->Data4[0],
92 clsid->Data4[1], clsid->Data4[2], clsid->Data4[3], clsid->Data4[4],
93 clsid->Data4[5], clsid->Data4[6], clsid->Data4[7]);
96 return S_OK;
99 static void cleanup_register_strtable(STRTABLEA *strtable)
101 int i;
102 for (i = 0; i < strtable->cEntries; i++) {
103 HeapFree(GetProcessHeap(), 0, strtable->pse[i].pszName);
104 HeapFree(GetProcessHeap(), 0, strtable->pse[i].pszValue);
105 if (!strtable->pse[i].pszName || !strtable->pse[i].pszValue)
106 return;
110 static HRESULT register_service(BOOL do_register)
112 static const WCHAR name[] = { 'B','I','T','S', 0 };
113 static const WCHAR path[] = { 's','v','c','h','o','s','t','.','e','x','e',
114 ' ','-','k',' ','n','e','t','s','v','c','s', 0 };
115 SC_HANDLE scm, service;
116 HRESULT hr = S_OK;
118 scm = OpenSCManagerW(NULL, NULL, SC_MANAGER_ALL_ACCESS);
119 if (!scm)
120 return SELFREG_E_CLASS;
122 if (do_register)
123 service = CreateServiceW(scm, name, name, SERVICE_ALL_ACCESS,
124 SERVICE_WIN32_OWN_PROCESS,
125 SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL,
126 path, NULL, NULL, NULL, NULL, NULL);
127 else
128 service = OpenServiceW(scm, name, DELETE);
131 CloseServiceHandle(scm);
132 if (!service)
133 return SELFREG_E_CLASS;
135 if (!do_register)
136 hr = DeleteService(service) ? S_OK : SELFREG_E_CLASS;
138 CloseServiceHandle(service);
139 return hr;
142 /* Use an INF file to register or unregister the DLL */
143 static HRESULT register_server(BOOL do_register)
145 HRESULT hr;
146 STRTABLEA strtable;
148 TRACE("(%x)\n", do_register);
150 hr = register_service(do_register);
151 if (FAILED(hr)) {
152 ERR("register_service failed: %d\n", GetLastError());
153 return hr;
156 hr = init_register_strtable(&strtable);
157 if (SUCCEEDED(hr))
158 hr = RegInstallA(hInst, do_register ? "RegisterDll" : "UnregisterDll",
159 &strtable);
160 cleanup_register_strtable(&strtable);
162 if (FAILED(hr))
163 ERR("RegInstall failed: %08x\n", hr);
165 return hr;
168 HRESULT WINAPI DllRegisterServer(void)
170 return register_server(TRUE);
173 HRESULT WINAPI DllUnregisterServer(void)
175 return register_server(FALSE);