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 dmusic.dll
00003  *
00004  * Copyright (C) 2003 John K. Hohm
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 "dmusic_private.h"
00022 #include "wine/unicode.h"
00023 
00024 WINE_DEFAULT_DEBUG_CHANNEL(dmusic);
00025 
00026 /*
00027  * Near the bottom of this file are the exported DllRegisterServer and
00028  * DllUnregisterServer, which make all this worthwhile.
00029  */
00030 
00031 /***********************************************************************
00032  *      interface for self-registering
00033  */
00034 struct regsvr_interface {
00035     IID const *iid;     /* NULL for end of list */
00036     LPCSTR name;        /* can be NULL to omit */
00037     IID const *base_iid;    /* can be NULL to omit */
00038     int num_methods;        /* can be <0 to omit */
00039     CLSID const *ps_clsid;  /* can be NULL to omit */
00040     CLSID const *ps_clsid32;    /* can be NULL to omit */
00041 };
00042 
00043 static HRESULT register_interfaces(struct regsvr_interface const *list);
00044 static HRESULT unregister_interfaces(struct regsvr_interface const *list);
00045 
00046 struct regsvr_coclass {
00047     CLSID const *clsid;     /* NULL for end of list */
00048     LPCSTR name;        /* can be NULL to omit */
00049     LPCSTR ips;         /* can be NULL to omit */
00050     LPCSTR ips32;       /* can be NULL to omit */
00051     LPCSTR ips32_tmodel;    /* can be NULL to omit */
00052     LPCSTR progid;      /* can be NULL to omit */
00053     LPCSTR viprogid;        /* can be NULL to omit */
00054     LPCSTR progid_extra;    /* can be NULL to omit */
00055 };
00056 
00057 static HRESULT register_coclasses(struct regsvr_coclass const *list);
00058 static HRESULT unregister_coclasses(struct regsvr_coclass const *list);
00059 
00060 /***********************************************************************
00061  *      static string constants
00062  */
00063 static WCHAR const interface_keyname[10] = {
00064     'I', 'n', 't', 'e', 'r', 'f', 'a', 'c', 'e', 0 };
00065 static WCHAR const base_ifa_keyname[14] = {
00066     'B', 'a', 's', 'e', 'I', 'n', 't', 'e', 'r', 'f', 'a', 'c',
00067     'e', 0 };
00068 static WCHAR const num_methods_keyname[11] = {
00069     'N', 'u', 'm', 'M', 'e', 't', 'h', 'o', 'd', 's', 0 };
00070 static WCHAR const ps_clsid_keyname[15] = {
00071     'P', 'r', 'o', 'x', 'y', 'S', 't', 'u', 'b', 'C', 'l', 's',
00072     'i', 'd', 0 };
00073 static WCHAR const ps_clsid32_keyname[17] = {
00074     'P', 'r', 'o', 'x', 'y', 'S', 't', 'u', 'b', 'C', 'l', 's',
00075     'i', 'd', '3', '2', 0 };
00076 static WCHAR const clsid_keyname[6] = {
00077     'C', 'L', 'S', 'I', 'D', 0 };
00078 static WCHAR const curver_keyname[7] = {
00079     'C', 'u', 'r', 'V', 'e', 'r', 0 };
00080 static WCHAR const ips_keyname[13] = {
00081     'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r',
00082     0 };
00083 static WCHAR const ips32_keyname[15] = {
00084     'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r',
00085     '3', '2', 0 };
00086 static WCHAR const progid_keyname[7] = {
00087     'P', 'r', 'o', 'g', 'I', 'D', 0 };
00088 static WCHAR const viprogid_keyname[25] = {
00089     'V', 'e', 'r', 's', 'i', 'o', 'n', 'I', 'n', 'd', 'e', 'p',
00090     'e', 'n', 'd', 'e', 'n', 't', 'P', 'r', 'o', 'g', 'I', 'D',
00091     0 };
00092 static char const tmodel_valuename[] = "ThreadingModel";
00093 
00094 /***********************************************************************
00095  *      static helper functions
00096  */
00097 static LONG register_key_guid(HKEY base, WCHAR const *name, GUID const *guid);
00098 static LONG register_key_defvalueW(HKEY base, WCHAR const *name,
00099                    WCHAR const *value);
00100 static LONG register_key_defvalueA(HKEY base, WCHAR const *name,
00101                    char const *value);
00102 static LONG register_progid(WCHAR const *clsid,
00103                 char const *progid, char const *curver_progid,
00104                 char const *name, char const *extra);
00105 
00106 /***********************************************************************
00107  *      register_interfaces
00108  */
00109 static HRESULT register_interfaces(struct regsvr_interface const *list) {
00110     LONG res = ERROR_SUCCESS;
00111     HKEY interface_key;
00112 
00113     res = RegCreateKeyExW(HKEY_CLASSES_ROOT, interface_keyname, 0, NULL, 0,
00114               KEY_READ | KEY_WRITE, NULL, &interface_key, NULL);
00115     if (res != ERROR_SUCCESS) goto error_return;
00116 
00117     for (; res == ERROR_SUCCESS && list->iid; ++list) {
00118     WCHAR buf[39];
00119     HKEY iid_key;
00120 
00121     StringFromGUID2(list->iid, buf, 39);
00122     res = RegCreateKeyExW(interface_key, buf, 0, NULL, 0,
00123                   KEY_READ | KEY_WRITE, NULL, &iid_key, NULL);
00124     if (res != ERROR_SUCCESS) goto error_close_interface_key;
00125 
00126     if (list->name) {
00127         res = RegSetValueExA(iid_key, NULL, 0, REG_SZ,
00128                  (CONST BYTE*)(list->name),
00129                  strlen(list->name) + 1);
00130         if (res != ERROR_SUCCESS) goto error_close_iid_key;
00131     }
00132 
00133     if (list->base_iid) {
00134         res = register_key_guid(iid_key, base_ifa_keyname, list->base_iid);
00135         if (res != ERROR_SUCCESS) goto error_close_iid_key;
00136     }
00137 
00138     if (0 <= list->num_methods) {
00139         static WCHAR const fmt[3] = { '%', 'd', 0 };
00140         HKEY key;
00141 
00142         res = RegCreateKeyExW(iid_key, num_methods_keyname, 0, NULL, 0,
00143                   KEY_READ | KEY_WRITE, NULL, &key, NULL);
00144         if (res != ERROR_SUCCESS) goto error_close_iid_key;
00145 
00146         sprintfW(buf, fmt, list->num_methods);
00147         res = RegSetValueExW(key, NULL, 0, REG_SZ,
00148                  (CONST BYTE*)buf,
00149                  (lstrlenW(buf) + 1) * sizeof(WCHAR));
00150         RegCloseKey(key);
00151 
00152         if (res != ERROR_SUCCESS) goto error_close_iid_key;
00153     }
00154 
00155     if (list->ps_clsid) {
00156         res = register_key_guid(iid_key, ps_clsid_keyname, list->ps_clsid);
00157         if (res != ERROR_SUCCESS) goto error_close_iid_key;
00158     }
00159 
00160     if (list->ps_clsid32) {
00161         res = register_key_guid(iid_key, ps_clsid32_keyname, list->ps_clsid32);
00162         if (res != ERROR_SUCCESS) goto error_close_iid_key;
00163     }
00164 
00165     error_close_iid_key:
00166     RegCloseKey(iid_key);
00167     }
00168 
00169 error_close_interface_key:
00170     RegCloseKey(interface_key);
00171 error_return:
00172     return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
00173 }
00174 
00175 /***********************************************************************
00176  *      unregister_interfaces
00177  */
00178 static HRESULT unregister_interfaces(struct regsvr_interface const *list) {
00179     LONG res = ERROR_SUCCESS;
00180     HKEY interface_key;
00181 
00182     res = RegOpenKeyExW(HKEY_CLASSES_ROOT, interface_keyname, 0,
00183             KEY_READ | KEY_WRITE, &interface_key);
00184     if (res == ERROR_FILE_NOT_FOUND) return S_OK;
00185     if (res != ERROR_SUCCESS) goto error_return;
00186 
00187     for (; res == ERROR_SUCCESS && list->iid; ++list) {
00188     WCHAR buf[39];
00189 
00190     StringFromGUID2(list->iid, buf, 39);
00191     res = RegDeleteTreeW(interface_key, buf);
00192     if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
00193     }
00194 
00195     RegCloseKey(interface_key);
00196 error_return:
00197     return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
00198 }
00199 
00200 /***********************************************************************
00201  *      register_coclasses
00202  */
00203 static HRESULT register_coclasses(struct regsvr_coclass const *list) {
00204     LONG res = ERROR_SUCCESS;
00205     HKEY coclass_key;
00206 
00207     res = RegCreateKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0, NULL, 0,
00208               KEY_READ | KEY_WRITE, NULL, &coclass_key, NULL);
00209     if (res != ERROR_SUCCESS) goto error_return;
00210 
00211     for (; res == ERROR_SUCCESS && list->clsid; ++list) {
00212     WCHAR buf[39];
00213     HKEY clsid_key;
00214 
00215     StringFromGUID2(list->clsid, buf, 39);
00216     res = RegCreateKeyExW(coclass_key, buf, 0, NULL, 0,
00217                   KEY_READ | KEY_WRITE, NULL, &clsid_key, NULL);
00218     if (res != ERROR_SUCCESS) goto error_close_coclass_key;
00219 
00220     if (list->name) {
00221         res = RegSetValueExA(clsid_key, NULL, 0, REG_SZ,
00222                  (CONST BYTE*)(list->name),
00223                  strlen(list->name) + 1);
00224         if (res != ERROR_SUCCESS) goto error_close_clsid_key;
00225     }
00226 
00227     if (list->ips) {
00228         res = register_key_defvalueA(clsid_key, ips_keyname, list->ips);
00229         if (res != ERROR_SUCCESS) goto error_close_clsid_key;
00230     }
00231 
00232     if (list->ips32) {
00233         HKEY ips32_key;
00234 
00235         res = RegCreateKeyExW(clsid_key, ips32_keyname, 0, NULL, 0,
00236                   KEY_READ | KEY_WRITE, NULL,
00237                   &ips32_key, NULL);
00238         if (res != ERROR_SUCCESS) goto error_close_clsid_key;
00239 
00240         res = RegSetValueExA(ips32_key, NULL, 0, REG_SZ,
00241                  (CONST BYTE*)list->ips32,
00242                  lstrlenA(list->ips32) + 1);
00243         if (res == ERROR_SUCCESS && list->ips32_tmodel)
00244         res = RegSetValueExA(ips32_key, tmodel_valuename, 0, REG_SZ,
00245                      (CONST BYTE*)list->ips32_tmodel,
00246                      strlen(list->ips32_tmodel) + 1);
00247         RegCloseKey(ips32_key);
00248         if (res != ERROR_SUCCESS) goto error_close_clsid_key;
00249     }
00250 
00251     if (list->progid) {
00252         res = register_key_defvalueA(clsid_key, progid_keyname,
00253                      list->progid);
00254         if (res != ERROR_SUCCESS) goto error_close_clsid_key;
00255 
00256         res = register_progid(buf, list->progid, NULL,
00257                   list->name, list->progid_extra);
00258         if (res != ERROR_SUCCESS) goto error_close_clsid_key;
00259     }
00260 
00261     if (list->viprogid) {
00262         res = register_key_defvalueA(clsid_key, viprogid_keyname,
00263                      list->viprogid);
00264         if (res != ERROR_SUCCESS) goto error_close_clsid_key;
00265 
00266         res = register_progid(buf, list->viprogid, list->progid,
00267                   list->name, list->progid_extra);
00268         if (res != ERROR_SUCCESS) goto error_close_clsid_key;
00269     }
00270 
00271     error_close_clsid_key:
00272     RegCloseKey(clsid_key);
00273     }
00274 
00275 error_close_coclass_key:
00276     RegCloseKey(coclass_key);
00277 error_return:
00278     return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
00279 }
00280 
00281 /***********************************************************************
00282  *      unregister_coclasses
00283  */
00284 static HRESULT unregister_coclasses(struct regsvr_coclass const *list) {
00285     LONG res = ERROR_SUCCESS;
00286     HKEY coclass_key;
00287 
00288     res = RegOpenKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0,
00289             KEY_READ | KEY_WRITE, &coclass_key);
00290     if (res == ERROR_FILE_NOT_FOUND) return S_OK;
00291     if (res != ERROR_SUCCESS) goto error_return;
00292 
00293     for (; res == ERROR_SUCCESS && list->clsid; ++list) {
00294     WCHAR buf[39];
00295 
00296     StringFromGUID2(list->clsid, buf, 39);
00297     res = RegDeleteTreeW(coclass_key, buf);
00298     if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
00299     if (res != ERROR_SUCCESS) goto error_close_coclass_key;
00300 
00301     if (list->progid) {
00302         res = RegDeleteTreeA(HKEY_CLASSES_ROOT, list->progid);
00303         if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
00304         if (res != ERROR_SUCCESS) goto error_close_coclass_key;
00305     }
00306 
00307     if (list->viprogid) {
00308         res = RegDeleteTreeA(HKEY_CLASSES_ROOT, list->viprogid);
00309         if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
00310         if (res != ERROR_SUCCESS) goto error_close_coclass_key;
00311     }
00312     }
00313 
00314 error_close_coclass_key:
00315     RegCloseKey(coclass_key);
00316 error_return:
00317     return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
00318 }
00319 
00320 /***********************************************************************
00321  *      regsvr_key_guid
00322  */
00323 static LONG register_key_guid(HKEY base, WCHAR const *name, GUID const *guid) {
00324     WCHAR buf[39];
00325 
00326     StringFromGUID2(guid, buf, 39);
00327     return register_key_defvalueW(base, name, buf);
00328 }
00329 
00330 /***********************************************************************
00331  *      regsvr_key_defvalueW
00332  */
00333 static LONG register_key_defvalueW(
00334     HKEY base,
00335     WCHAR const *name,
00336     WCHAR const *value) {
00337     LONG res;
00338     HKEY key;
00339 
00340     res = RegCreateKeyExW(base, name, 0, NULL, 0,
00341               KEY_READ | KEY_WRITE, NULL, &key, NULL);
00342     if (res != ERROR_SUCCESS) return res;
00343     res = RegSetValueExW(key, NULL, 0, REG_SZ, (CONST BYTE*)value,
00344              (lstrlenW(value) + 1) * sizeof(WCHAR));
00345     RegCloseKey(key);
00346     return res;
00347 }
00348 
00349 /***********************************************************************
00350  *      regsvr_key_defvalueA
00351  */
00352 static LONG register_key_defvalueA(
00353     HKEY base,
00354     WCHAR const *name,
00355     char const *value) {
00356     LONG res;
00357     HKEY key;
00358 
00359     res = RegCreateKeyExW(base, name, 0, NULL, 0,
00360               KEY_READ | KEY_WRITE, NULL, &key, NULL);
00361     if (res != ERROR_SUCCESS) return res;
00362     res = RegSetValueExA(key, NULL, 0, REG_SZ, (CONST BYTE*)value,
00363              lstrlenA(value) + 1);
00364     RegCloseKey(key);
00365     return res;
00366 }
00367 
00368 /***********************************************************************
00369  *      regsvr_progid
00370  */
00371 static LONG register_progid(
00372     WCHAR const *clsid,
00373     char const *progid,
00374     char const *curver_progid,
00375     char const *name,
00376     char const *extra) {
00377     LONG res;
00378     HKEY progid_key;
00379 
00380     res = RegCreateKeyExA(HKEY_CLASSES_ROOT, progid, 0,
00381               NULL, 0, KEY_READ | KEY_WRITE, NULL,
00382               &progid_key, NULL);
00383     if (res != ERROR_SUCCESS) return res;
00384 
00385     if (name) {
00386     res = RegSetValueExA(progid_key, NULL, 0, REG_SZ,
00387                  (CONST BYTE*)name, strlen(name) + 1);
00388     if (res != ERROR_SUCCESS) goto error_close_progid_key;
00389     }
00390 
00391     if (clsid) {
00392     res = register_key_defvalueW(progid_key, clsid_keyname, clsid);
00393     if (res != ERROR_SUCCESS) goto error_close_progid_key;
00394     }
00395 
00396     if (curver_progid) {
00397     res = register_key_defvalueA(progid_key, curver_keyname,
00398                      curver_progid);
00399     if (res != ERROR_SUCCESS) goto error_close_progid_key;
00400     }
00401 
00402     if (extra) {
00403     HKEY extra_key;
00404 
00405     res = RegCreateKeyExA(progid_key, extra, 0,
00406                   NULL, 0, KEY_READ | KEY_WRITE, NULL,
00407                   &extra_key, NULL);
00408     if (res == ERROR_SUCCESS)
00409         RegCloseKey(extra_key);
00410     }
00411 
00412 error_close_progid_key:
00413     RegCloseKey(progid_key);
00414     return res;
00415 }
00416 
00417 /***********************************************************************
00418  *      coclass list
00419  */
00420 static struct regsvr_coclass const coclass_list[] = {
00421     {   &CLSID_DirectMusic,
00422     "DirectMusic",
00423     NULL,
00424     "dmusic.dll",
00425     "Both",
00426     "Microsoft.DirectMusic.1",
00427     "Microsoft.DirectMusic"
00428     },
00429     {   &CLSID_DirectMusicCollection,
00430     "DirectMusicCollection",
00431     NULL,
00432     "dmusic.dll",
00433     "Both",
00434     "Microsoft.DirectMusicCollection.1",
00435     "Microsoft.DirectMusicCollection"
00436     },
00437     { NULL }            /* list terminator */
00438 };
00439 
00440 /***********************************************************************
00441  *      interface list
00442  */
00443 
00444 static struct regsvr_interface const interface_list[] = {
00445     { NULL }            /* list terminator */
00446 };
00447 
00448 /***********************************************************************
00449  *      DllRegisterServer (DMUSIC.3)
00450  */
00451 HRESULT WINAPI DllRegisterServer(void)
00452 {
00453     HRESULT hr;
00454 
00455     TRACE("\n");
00456 
00457     hr = register_coclasses(coclass_list);
00458     if (SUCCEEDED(hr))
00459     hr = register_interfaces(interface_list);
00460     return hr;
00461 }
00462 
00463 /***********************************************************************
00464  *      DllUnregisterServer (DMUSIC.4)
00465  */
00466 HRESULT WINAPI DllUnregisterServer(void)
00467 {
00468     HRESULT hr;
00469 
00470     TRACE("\n");
00471 
00472     hr = unregister_coclasses(coclass_list);
00473     if (SUCCEEDED(hr))
00474     hr = unregister_interfaces(interface_list);
00475     return hr;
00476 }

Generated on Thu May 24 2012 04:21:40 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.