home *** CD-ROM | disk | FTP | other *** search
/ Java Developer's Companion / Java Developer's Companion.iso / binaries / Windows / jsdk / src / sun / servlet / isapi / Registry.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-18  |  2.2 KB  |  85 lines

  1. /*
  2.  * @(#)Registry.cpp    1.2 97/05/13
  3.  * 
  4.  * Copyright (c) 1995-1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  * CopyrightVersion 1.0
  20.  */
  21.  
  22. #include <stdio.h>
  23. #include <wtypes.h>
  24. #include <winnt.h>
  25. #include <winreg.h>
  26. #include <winbase.h>
  27.  
  28. extern char *CLASSPATH, *MAINCLASS, *PATH, *PROPFILE;
  29.  
  30. int getRegistryValues() {
  31.     HKEY mainKey;
  32.     DWORD res;
  33.     long retval;
  34.  
  35.     retval = RegCreateKeyEx(HKEY_LOCAL_MACHINE,
  36.                 "SOFTWARE\\JavaSoft\\JSDK",
  37.                 0,
  38.                 "JSDK",
  39.                 REG_OPTION_NON_VOLATILE,
  40.                 KEY_ALL_ACCESS,
  41.                 NULL,
  42.                 &mainKey,
  43.                 &res);
  44.     if (retval != ERROR_SUCCESS) {
  45.         char bbuf[1024];
  46.     unsigned long bbb = 1024;
  47.     unsigned long typeis = FORMAT_MESSAGE_FROM_HMODULE;
  48.     memset(bbuf, 0, 1024);
  49.         FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
  50.               &typeis,
  51.               GetLastError(),
  52.               0,
  53.               bbuf,
  54.               bbb,
  55.               NULL);
  56.               
  57.         return 0;
  58.     }
  59.  
  60.     char keybuf[16], valuebuf[1024];
  61.     unsigned long keylen = 16, valuelen = 1024, typevar = REG_SZ;
  62.     int iter = 0;
  63.     while ((retval = RegEnumValue(mainKey,
  64.                   iter++,
  65.                   keybuf,
  66.                   &keylen,
  67.                   NULL,
  68.                   &typevar,
  69.                   (unsigned char *)valuebuf,
  70.                   &valuelen)) != ERROR_NO_MORE_ITEMS) {
  71.         if (!strcmp(keybuf, "ClassPath")) {
  72.         CLASSPATH = strdup(valuebuf);
  73.     } else if (!strcmp(keybuf, "MainClass")) {
  74.         MAINCLASS = strdup(valuebuf);
  75.     } else if (!strcmp(keybuf, "PropFile")) {
  76.         PROPFILE = strdup(valuebuf);
  77.     } else if (!strcmp(keybuf, "Path")) {
  78.         PATH = strdup(valuebuf);
  79.     }
  80.     keylen = 16;
  81.     valuelen = 1024;
  82.     }
  83.     return 1;
  84. }
  85.