ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

regsvr.c
Go to the documentation of this file.
00001 /*
00002  *        self-registerable dll functions for qedit.dll
00003  *
00004  * Copyright (C) 2008 Google (Lei Zhang)
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00019  */
00020 
00021 #include "qedit_private.h"
00022 #include "winreg.h"
00023 
00024 #include "wine/debug.h"
00025 
00026 WINE_DEFAULT_DEBUG_CHANNEL(qedit);
00027 
00028 struct regsvr_coclass
00029 {
00030     CLSID const *clsid;   /* NULL for end of list */
00031     LPCSTR name;          /* can be NULL to omit */
00032     LPCSTR ips;           /* can be NULL to omit */
00033     LPCSTR ips32;         /* can be NULL to omit */
00034     LPCSTR ips32_tmodel;  /* can be NULL to omit */
00035     LPCSTR progid;        /* can be NULL to omit */
00036     LPCSTR viprogid;      /* can be NULL to omit */
00037     LPCSTR progid_extra;  /* can be NULL to omit */
00038 };
00039 
00040 static HRESULT register_coclasses(struct regsvr_coclass const *list);
00041 static HRESULT unregister_coclasses(struct regsvr_coclass const *list);
00042 
00043 /***********************************************************************
00044  *              static string constants
00045  */
00046 static WCHAR const clsid_keyname[6] = {
00047   'C', 'L', 'S', 'I', 'D', 0 };
00048 static WCHAR const curver_keyname[7] = {
00049     'C', 'u', 'r', 'V', 'e', 'r', 0 };
00050 static WCHAR const ips_keyname[13] = {
00051   'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r', 0 };
00052 static WCHAR const ips32_keyname[15] = {
00053     'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r', '3', '2', 0 };
00054 static WCHAR const progid_keyname[7] = {
00055     'P', 'r', 'o', 'g', 'I', 'D', 0 };
00056 static WCHAR const viprogid_keyname[25] = {
00057     'V', 'e', 'r', 's', 'i', 'o', 'n', 'I', 'n', 'd', 'e', 'p',
00058     'e', 'n', 'd', 'e', 'n', 't', 'P', 'r', 'o', 'g', 'I', 'D',
00059     0 };
00060 static char const tmodel_valuename[] = "ThreadingModel";
00061 
00062 /***********************************************************************
00063  *              static helper functions
00064  */
00065 static LONG register_key_defvalueW(HKEY base, WCHAR const *name,
00066                                    WCHAR const *value);
00067 static LONG register_key_defvalueA(HKEY base, WCHAR const *name,
00068                                    char const *value);
00069 static LONG register_progid(WCHAR const *clsid,
00070                             char const *progid, char const *curver_progid,
00071                             char const *name, char const *extra);
00072 
00073 
00074 
00075 /***********************************************************************
00076  *              register_coclasses
00077  */
00078 static HRESULT register_coclasses(struct regsvr_coclass const *list)
00079 {
00080     LONG res = ERROR_SUCCESS;
00081     HKEY coclass_key;
00082 
00083     res = RegCreateKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0, NULL, 0,
00084                           KEY_READ | KEY_WRITE, NULL, &coclass_key, NULL);
00085     if (res != ERROR_SUCCESS) goto error_return;
00086 
00087     for (; res == ERROR_SUCCESS && list->clsid; ++list) {
00088         WCHAR buf[39];
00089         HKEY clsid_key;
00090 
00091         StringFromGUID2(list->clsid, buf, 39);
00092         res = RegCreateKeyExW(coclass_key, buf, 0, NULL, 0,
00093                               KEY_READ | KEY_WRITE, NULL, &clsid_key, NULL);
00094         if (res != ERROR_SUCCESS) goto error_close_coclass_key;
00095 
00096         if (list->name) {
00097             res = RegSetValueExA(clsid_key, NULL, 0, REG_SZ,
00098                                  (CONST BYTE*)(list->name),
00099                                  strlen(list->name) + 1);
00100             if (res != ERROR_SUCCESS) goto error_close_clsid_key;
00101         }
00102 
00103         if (list->ips) {
00104             res = register_key_defvalueA(clsid_key, ips_keyname, list->ips);
00105             if (res != ERROR_SUCCESS) goto error_close_clsid_key;
00106         }
00107 
00108         if (list->ips32) {
00109             HKEY ips32_key;
00110 
00111             res = RegCreateKeyExW(clsid_key, ips32_keyname, 0, NULL, 0,
00112                                   KEY_READ | KEY_WRITE, NULL,
00113                                   &ips32_key, NULL);
00114             if (res != ERROR_SUCCESS) goto error_close_clsid_key;
00115 
00116             res = RegSetValueExA(ips32_key, NULL, 0, REG_SZ,
00117                                  (CONST BYTE*)list->ips32,
00118                                  lstrlenA(list->ips32) + 1);
00119             if (res == ERROR_SUCCESS && list->ips32_tmodel)
00120                 res = RegSetValueExA(ips32_key, tmodel_valuename, 0, REG_SZ,
00121                                      (CONST BYTE*)list->ips32_tmodel,
00122                                      strlen(list->ips32_tmodel) + 1);
00123             RegCloseKey(ips32_key);
00124             if (res != ERROR_SUCCESS) goto error_close_clsid_key;
00125         }
00126 
00127         if (list->progid) {
00128             res = register_key_defvalueA(clsid_key, progid_keyname,
00129                                          list->progid);
00130             if (res != ERROR_SUCCESS) goto error_close_clsid_key;
00131 
00132             res = register_progid(buf, list->progid, NULL,
00133                                   list->name, list->progid_extra);
00134             if (res != ERROR_SUCCESS) goto error_close_clsid_key;
00135         }
00136 
00137         if (list->viprogid) {
00138             res = register_key_defvalueA(clsid_key, viprogid_keyname,
00139                                          list->viprogid);
00140             if (res != ERROR_SUCCESS) goto error_close_clsid_key;
00141 
00142             res = register_progid(buf, list->viprogid, list->progid,
00143                                   list->name, list->progid_extra);
00144             if (res != ERROR_SUCCESS) goto error_close_clsid_key;
00145         }
00146 
00147 error_close_clsid_key:
00148         RegCloseKey(clsid_key);
00149     }
00150 
00151 error_close_coclass_key:
00152     RegCloseKey(coclass_key);
00153 error_return:
00154     return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
00155 }
00156 
00157 /***********************************************************************
00158  *              unregister_coclasses
00159  */
00160 static HRESULT unregister_coclasses(struct regsvr_coclass const *list)
00161 {
00162     LONG res = ERROR_SUCCESS;
00163     HKEY coclass_key;
00164 
00165     res = RegOpenKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0,
00166                         KEY_READ | KEY_WRITE, &coclass_key);
00167     if (res == ERROR_FILE_NOT_FOUND) return S_OK;
00168     if (res != ERROR_SUCCESS) goto error_return;
00169 
00170     for (; res == ERROR_SUCCESS && list->clsid; ++list) {
00171         WCHAR buf[39];
00172 
00173         StringFromGUID2(list->clsid, buf, 39);
00174         res = RegDeleteTreeW(coclass_key, buf);
00175         if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
00176         if (res != ERROR_SUCCESS) goto error_close_coclass_key;
00177 
00178         if (list->progid) {
00179             res = RegDeleteTreeA(HKEY_CLASSES_ROOT, list->progid);
00180             if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
00181             if (res != ERROR_SUCCESS) goto error_close_coclass_key;
00182         }
00183 
00184         if (list->viprogid) {
00185             res = RegDeleteTreeA(HKEY_CLASSES_ROOT, list->viprogid);
00186             if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
00187             if (res != ERROR_SUCCESS) goto error_close_coclass_key;
00188         }
00189     }
00190 
00191 error_close_coclass_key:
00192     RegCloseKey(coclass_key);
00193 error_return:
00194     return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
00195 }
00196 
00197 /***********************************************************************
00198  *              regsvr_key_defvalueW
00199  */
00200 static LONG register_key_defvalueW(
00201     HKEY base,
00202     WCHAR const *name,
00203     WCHAR const *value)
00204 {
00205     LONG res;
00206     HKEY key;
00207 
00208     res = RegCreateKeyExW(base, name, 0, NULL, 0,
00209                           KEY_READ | KEY_WRITE, NULL, &key, NULL);
00210     if (res != ERROR_SUCCESS) return res;
00211     res = RegSetValueExW(key, NULL, 0, REG_SZ, (CONST BYTE*)value,
00212                          (lstrlenW(value) + 1) * sizeof(WCHAR));
00213     RegCloseKey(key);
00214     return res;
00215 }
00216 
00217 /***********************************************************************
00218  *              regsvr_key_defvalueA
00219  */
00220 static LONG register_key_defvalueA(
00221     HKEY base,
00222     WCHAR const *name,
00223     char const *value)
00224 {
00225   LONG res;
00226   HKEY key;
00227 
00228   res = RegCreateKeyExW(base, name, 0, NULL, 0,
00229                         KEY_READ | KEY_WRITE, NULL, &key, NULL);
00230   if (res != ERROR_SUCCESS) return res;
00231   res = RegSetValueExA(key, NULL, 0, REG_SZ, (CONST BYTE*)value,
00232                        lstrlenA(value) + 1);
00233   RegCloseKey(key);
00234   return res;
00235 }
00236 
00237 /***********************************************************************
00238  *              regsvr_progid
00239  */
00240 static LONG register_progid(
00241     WCHAR const *clsid,
00242     char const *progid,
00243     char const *curver_progid,
00244     char const *name,
00245     char const *extra)
00246 {
00247     LONG res;
00248     HKEY progid_key;
00249 
00250     res = RegCreateKeyExA(HKEY_CLASSES_ROOT, progid, 0,
00251                           NULL, 0, KEY_READ | KEY_WRITE, NULL,
00252                           &progid_key, NULL);
00253     if (res != ERROR_SUCCESS) return res;
00254 
00255     if (name) {
00256         res = RegSetValueExA(progid_key, NULL, 0, REG_SZ,
00257                              (CONST BYTE*)name, strlen(name) + 1);
00258         if (res != ERROR_SUCCESS) goto error_close_progid_key;
00259     }
00260 
00261     if (clsid) {
00262         res = register_key_defvalueW(progid_key, clsid_keyname, clsid);
00263         if (res != ERROR_SUCCESS) goto error_close_progid_key;
00264     }
00265 
00266     if (curver_progid) {
00267         res = register_key_defvalueA(progid_key, curver_keyname,
00268                                      curver_progid);
00269         if (res != ERROR_SUCCESS) goto error_close_progid_key;
00270     }
00271 
00272     if (extra) {
00273         HKEY extra_key;
00274 
00275         res = RegCreateKeyExA(progid_key, extra, 0,
00276                               NULL, 0, KEY_READ | KEY_WRITE, NULL,
00277                               &extra_key, NULL);
00278         if (res == ERROR_SUCCESS)
00279             RegCloseKey(extra_key);
00280     }
00281 
00282 error_close_progid_key:
00283     RegCloseKey(progid_key);
00284     return res;
00285 }
00286 
00287 /***********************************************************************
00288  *              coclass list
00289  */
00290 static struct regsvr_coclass const coclass_list[] = {
00291     {   &CLSID_MediaDet,
00292         "MediaDet",
00293         NULL,
00294         "qedit.dll",
00295         "Both"
00296     },
00297     {   &CLSID_SampleGrabber,
00298         "Sample Grabber",
00299         NULL,
00300         "qedit.dll",
00301         "Both"
00302     },
00303     { NULL }                    /* list terminator */
00304 };
00305 
00306 /***********************************************************************
00307  *                DllRegisterServer (QEDIT.@)
00308  */
00309 HRESULT WINAPI DllRegisterServer(void)
00310 {
00311     HRESULT hr;
00312 
00313     TRACE("\n");
00314 
00315     hr = register_coclasses(coclass_list);
00316     return hr;
00317 }
00318 
00319 /***********************************************************************
00320  *                DllUnregisterServer (QEDIT.@)
00321  */
00322 HRESULT WINAPI DllUnregisterServer(void)
00323 {
00324     HRESULT hr;
00325 
00326     TRACE("\n");
00327 
00328     hr = unregister_coclasses(coclass_list);
00329     return hr;
00330 }

Generated on Sun May 27 2012 04:21:33 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.