~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/wiaservc/wiaservc_main.c

Version: ~ [ wine-1.5.30 ] ~ [ wine-1.5.29 ] ~ [ wine-1.5.28 ] ~ [ wine-1.5.27 ] ~ [ wine-1.5.26 ] ~ [ wine-1.5.25 ] ~ [ wine-1.5.24 ] ~ [ wine-1.5.23 ] ~ [ wine-1.5.22 ] ~ [ wine-1.5.21 ] ~ [ wine-1.5.20 ] ~ [ wine-1.5.19 ] ~ [ wine-1.5.18 ] ~ [ wine-1.5.17 ] ~ [ wine-1.5.16 ] ~ [ wine-1.5.15 ] ~ [ wine-1.5.14 ] ~ [ wine-1.5.13 ] ~ [ wine-1.5.12 ] ~ [ wine-1.5.11 ] ~ [ wine-1.5.10 ] ~ [ wine-1.5.9 ] ~ [ wine-1.5.8 ] ~ [ wine-1.5.7 ] ~ [ wine-1.4.1 ] ~ [ wine-1.5.6 ] ~ [ wine-1.5.5 ] ~ [ wine-1.5.4 ] ~ [ wine-1.5.3 ] ~ [ wine-1.5.2 ] ~ [ wine-1.5.1 ] ~ [ wine-1.5.0 ] ~ [ wine-1.4 ] ~ [ wine-1.4-rc6 ] ~ [ wine-1.4-rc5 ] ~ [ wine-1.4-rc4 ] ~ [ wine-1.4-rc3 ] ~ [ wine-1.4-rc2 ] ~ [ wine-1.4-rc1 ] ~ [ wine-1.3.37 ] ~ [ wine-1.3.36 ] ~ [ wine-1.3.35 ] ~ [ wine-1.3.34 ] ~ [ wine-1.3.33 ] ~ [ wine-1.3.32 ] ~ [ wine-1.3.31 ] ~ [ wine-1.3.30 ] ~ [ wine-1.3.29 ] ~ [ wine-1.3.28 ] ~ [ wine-1.3.27 ] ~ [ wine-1.3.26 ] ~ [ wine-1.3.25 ] ~ [ wine-1.3.24 ] ~ [ wine-1.3.23 ] ~ [ wine-1.3.22 ] ~ [ wine-1.3.21 ] ~ [ wine-1.3.20 ] ~ [ wine-1.3.19 ] ~ [ wine-1.3.18 ] ~ [ wine-1.2.3 ] ~ [ wine-1.3.17 ] ~ [ wine-1.3.16 ] ~ [ wine-1.3.15 ] ~ [ wine-1.3.14 ] ~ [ wine-1.3.13 ] ~ [ wine-1.3.12 ] ~ [ wine-1.3.11 ] ~ [ wine-1.3.10 ] ~ [ wine-1.3.9 ] ~ [ wine-1.2.2 ] ~ [ wine-1.3.8 ] ~ [ wine-1.3.7 ] ~ [ wine-1.3.6 ] ~ [ wine-1.3.5 ] ~ [ wine-1.2.1 ] ~ [ wine-1.3.4 ] ~ [ wine-1.3.3 ] ~ [ wine-1.3.2 ] ~ [ wine-1.3.1 ] ~ [ wine-1.3.0 ] ~ [ wine-1.2 ] ~ [ wine-1.2-rc7 ] ~ [ wine-1.2-rc6 ] ~ [ wine-1.2-rc5 ] ~ [ wine-1.2-rc4 ] ~ [ wine-1.2-rc3 ] ~ [ wine-1.2-rc2 ] ~ [ wine-1.2-rc1 ] ~ [ wine-1.1.44 ] ~ [ wine-1.1.43 ] ~ [ wine-1.1.42 ] ~ [ wine-1.1.41 ] ~ [ wine-1.1.40 ] ~ [ wine-1.1.39 ] ~ [ wine-1.1.38 ] ~ [ wine-1.1.37 ] ~ [ wine-1.1.36 ] ~ [ wine-1.1.35 ] ~ [ wine-1.1.34 ] ~ [ wine-1.1.33 ] ~ [ wine-1.1.32 ] ~ [ wine-1.1.31 ] ~ [ wine-1.1.30 ] ~ [ wine-1.1.29 ] ~ [ wine-1.1.28 ] ~ [ wine-1.1.27 ] ~ [ wine-1.1.26 ] ~ [ wine-1.1.25 ] ~ [ wine-1.1.24 ] ~ [ wine-1.1.23 ] ~ [ wine-1.1.22 ] ~ [ wine-1.1.21 ] ~ [ wine-1.1.20 ] ~ [ wine-1.1.19 ] ~ [ wine-1.1.18 ] ~ [ wine-1.1.17 ] ~ [ wine-1.1.16 ] ~ [ wine-1.1.15 ] ~ [ wine-1.1.14 ] ~ [ wine-1.1.13 ] ~ [ wine-1.1.12 ] ~ [ wine-1.1.11 ] ~ [ wine-1.1.10 ] ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~

  1 /*
  2  * Main DLL interface to WIA Device Manager
  3  *
  4  * Copyright 2009 Damjan Jovanovic
  5  *
  6  * This library is free software; you can redistribute it and/or
  7  * modify it under the terms of the GNU Lesser General Public
  8  * License as published by the Free Software Foundation; either
  9  * version 2.1 of the License, or (at your option) any later version.
 10  *
 11  * This library is distributed in the hope that it will be useful,
 12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 14  * Lesser General Public License for more details.
 15  *
 16  * You should have received a copy of the GNU Lesser General Public
 17  * License along with this library; if not, write to the Free Software
 18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 19  */
 20 
 21 #include <stdio.h>
 22 
 23 #include "objbase.h"
 24 #include "winuser.h"
 25 #include "winreg.h"
 26 #include "advpub.h"
 27 #include "olectl.h"
 28 #include "winsvc.h"
 29 
 30 #include "wia_lh.h"
 31 #include "initguid.h"
 32 
 33 #include "wiaservc_private.h"
 34 
 35 #include "wine/debug.h"
 36 
 37 WINE_DEFAULT_DEBUG_CHANNEL(wia);
 38 
 39 /* Handle to the base address of this DLL */
 40 static HINSTANCE hInst;
 41 
 42 /* Entry point for DLL */
 43 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
 44 {
 45     TRACE("(%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
 46 
 47     switch (fdwReason)
 48     {
 49         case DLL_WINE_PREATTACH:
 50             return FALSE;  /* prefer native version */
 51         case DLL_PROCESS_ATTACH:
 52             DisableThreadLibraryCalls(hinstDLL);
 53             hInst = hinstDLL;
 54             break;
 55         case DLL_PROCESS_DETACH:
 56             break;
 57     }
 58 
 59     return TRUE;
 60 }
 61 
 62 static HRESULT init_register_strtable(STRTABLEA *strtable)
 63 {
 64 #define CLSID_EXPANSION_ENTRY(id) { "CLSID_" #id, &CLSID_ ## id }
 65     static const struct {
 66         const char *name;
 67         const CLSID *clsid;
 68     } expns[] =  {
 69         CLSID_EXPANSION_ENTRY(WiaDevMgr)
 70     };
 71 #undef CLSID_EXPANSION_ENTRY
 72     static STRENTRYA pse[sizeof expns / sizeof expns[0]];
 73     DWORD i;
 74 
 75     strtable->cEntries = sizeof pse / sizeof pse[0];
 76     strtable->pse = pse;
 77     for (i = 0; i < strtable->cEntries; i++) {
 78         static const char dummy_sample[] = "{12345678-1234-1234-1234-123456789012}";
 79         const CLSID *clsid = expns[i].clsid;
 80         pse[i].pszName = wiaservc_strdup(expns[i].name);
 81         pse[i].pszValue = HeapAlloc(GetProcessHeap(), 0, sizeof dummy_sample);
 82         if (!pse[i].pszName || !pse[i].pszValue)
 83             return E_OUTOFMEMORY;
 84         sprintf(pse[i].pszValue, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
 85                 clsid->Data1, clsid->Data2, clsid->Data3, clsid->Data4[0],
 86                 clsid->Data4[1], clsid->Data4[2], clsid->Data4[3], clsid->Data4[4],
 87                 clsid->Data4[5], clsid->Data4[6], clsid->Data4[7]);
 88     }
 89 
 90     return S_OK;
 91 }
 92 
 93 static void cleanup_register_strtable(STRTABLEA *strtable)
 94 {
 95     DWORD i;
 96     for (i = 0; i < strtable->cEntries; i++) {
 97         HeapFree(GetProcessHeap(), 0, strtable->pse[i].pszName);
 98         HeapFree(GetProcessHeap(), 0, strtable->pse[i].pszValue);
 99         if (!strtable->pse[i].pszName || !strtable->pse[i].pszValue)
100             return;
101     }
102 }
103 
104 static HRESULT register_service(BOOL do_register)
105 {
106     static const WCHAR name[] = { 's','t','i','s','v','c', 0 };
107     static const WCHAR path[] = { 's','v','c','h','o','s','t','.','e','x','e',
108                                   ' ','-','k',' ','i','m','g','s','v','c', 0 };
109     SC_HANDLE scm, service;
110 
111     scm = OpenSCManagerW(NULL, NULL, SC_MANAGER_ALL_ACCESS);
112     if (!scm)
113         return SELFREG_E_CLASS;
114 
115     if (do_register)
116         service = CreateServiceW(scm, name, name, SERVICE_ALL_ACCESS,
117                                  SERVICE_WIN32_OWN_PROCESS,
118                                  SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL,
119                                  path, NULL, NULL, NULL, NULL, NULL);
120     else
121         service = OpenServiceW(scm, name, DELETE);
122 
123 
124     CloseServiceHandle(scm);
125     if (service)
126     {
127         if (!do_register) DeleteService(service);
128         CloseServiceHandle(service);
129     }
130     return S_OK;
131 }
132 
133 /* Use an INF file to register or unregister the DLL */
134 static HRESULT register_server(BOOL do_register)
135 {
136     HRESULT hr;
137     STRTABLEA strtable;
138     HMODULE hAdvpack;
139     HRESULT (WINAPI *pRegInstall)(HMODULE hm, LPCSTR pszSection, const STRTABLEA* pstTable);
140     static const WCHAR wszAdvpack[] = {'a','d','v','p','a','c','k','.','d','l','l',0};
141 
142     TRACE("(%x)\n", do_register);
143 
144     hr = register_service(do_register);
145     if (FAILED(hr)) {
146         ERR("register_service failed: %d\n", GetLastError());
147         return hr;
148     }
149 
150     hAdvpack = LoadLibraryW(wszAdvpack);
151     pRegInstall = (void *)GetProcAddress(hAdvpack, "RegInstall");
152 
153     hr = init_register_strtable(&strtable);
154     if (SUCCEEDED(hr))
155         hr = pRegInstall(hInst, do_register ? "RegisterDll" : "UnregisterDll",
156                          &strtable);
157     cleanup_register_strtable(&strtable);
158 
159     if (FAILED(hr))
160         ERR("RegInstall failed: %08x\n", hr);
161 
162     return hr;
163 }
164 
165 HRESULT WINAPI DllRegisterServer(void)
166 {
167     return register_server(TRUE);
168 }
169 
170 HRESULT WINAPI DllUnregisterServer(void)
171 {
172     return register_server(FALSE);
173 }
174 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.