Annotation of mstools/samples/ole/clidemo/register.c, revision 1.1.1.2

1.1       root        1: /*
                      2:  * register.c - Handles the Win 3.1 registration library.
                      3:  *
                      4:  * Created by Microsoft Corporation.
                      5:  * (c) Copyright Microsoft Corp. 1990 - 1992  All Rights Reserved
                      6:  */
                      7: 
                      8: //*** INCLUDES ***
                      9: 
                     10: #include <windows.h>
                     11: #include <ole.h>
                     12: 
                     13: #include "global.h"
                     14: #include "register.h"
                     15: #include "clidemo.h"    
                     16: #include "demorc.h"   
                     17: 
                     18: /****************************************************************************
                     19:  * RegGetClassId() - Retrieves the string name of a class.
                     20:  *
                     21:  * Retrieve the string name of a class. Classes are guarenteed to be 
                     22:  * in ASCII, but should not be used directly as a rule because they
                     23:  * might be meaningless if running non-English Windows.
                     24:  ***************************************************************************/
                     25: 
                     26: VOID FAR RegGetClassId(                //* ENTRY:
                     27:    LPSTR    lpstrName,                 //* destination string name of class
                     28:    LPSTR    lpstrClass                 //* source name of class
                     29: ){                                     //* LOCAL:
                     30:    DWORD    dwSize = KEYNAMESIZE;      //* size of keyname string 
                     31:    CHAR     szName[KEYNAMESIZE];       //* string name for class 
                     32: 
                     33:    if (!RegQueryValue(HKEY_CLASSES_ROOT, lpstrClass, (LPSTR)szName, &dwSize))
                     34:           lstrcpy(lpstrName, (LPSTR)szName);
                     35:    else
                     36:           lstrcpy(lpstrName, lpstrClass);
                     37: 
                     38: }
                     39: 
                     40: 
                     41: 
                     42: /***************************************************************************
                     43:  *  RegMakeFilterSpec() - Retrieves class-associated default extensions.
                     44:  *
                     45:  * Get the class-associated default extensions, and build a filter spec, 
                     46:  * to be used in the "Change Link" standard dialog box, which contains 
                     47:  * all the default extensions which are associated with the given class 
                     48:  * name.  Again, the class names are guaranteed to be in ASCII.
                     49:  *
                     50:  * Returns int - The index idFilterIndex states which filter item 
                     51:  *               matches the extension, or 0 if none is found.
                     52:  ***************************************************************************/
                     53: 
                     54: INT FAR RegMakeFilterSpec(             //* ENTRY:
                     55:    LPSTR          lpstrClass,          //* class name
                     56:    LPSTR          lpstrExt,            //* file extension
                     57:    LPSTR          lpstrFilterSpec      //* destination filter spec
                     58: ){                                     //* LOCAL:
                     59:    DWORD          dwSize;              //* size of reg request
                     60:    CHAR           szClass[KEYNAMESIZE];//* class name 
                     61:    CHAR           szName[KEYNAMESIZE]; //* name of subkey 
                     62:    CHAR           szString[KEYNAMESIZE];//* name of subkey 
                     63:    INT            i;                    //* index of subkey query 
                     64:    INT            idWhich = 0;          //* index of combo box item 
                     65:    INT            idFilterIndex = 0;    //* index to filter matching extension 
                     66: 
                     67:    for (i = 0; !RegEnumKey(HKEY_CLASSES_ROOT, i++, szName, KEYNAMESIZE); ) 
                     68:    {
                     69:       if (  *szName == '.'             //* Default Extension...
                     70:             && (dwSize = KEYNAMESIZE)
                     71:             && !RegQueryValue(HKEY_CLASSES_ROOT, szName, szClass, &dwSize)
                     72:             && (!lpstrClass || !lstrcmpi(lpstrClass, szClass))
                     73:             && (dwSize = KEYNAMESIZE)
                     74:             && !RegQueryValue(HKEY_CLASSES_ROOT, szClass, szString, &dwSize)) 
                     75:       {
                     76:          idWhich++;    
                     77: 
                     78:          if (lpstrExt && !lstrcmpi(lpstrExt, szName))
                     79:             idFilterIndex = idWhich;
                     80:                                        //* Copy over "<Class Name String> 
                     81:                                        //* (*<Default Extension>)"
                     82:                                        //* e.g. "Server Picture (*.PIC)"
                     83:          lstrcpy(lpstrFilterSpec, szString);
                     84:          lstrcat(lpstrFilterSpec, " (*");
                     85:          lstrcat(lpstrFilterSpec, szName);
                     86:          lstrcat(lpstrFilterSpec, ")");
                     87:          lpstrFilterSpec += lstrlen(lpstrFilterSpec) + 1;
                     88:                                        //* Copy over "*<Default Extension>" 
                     89:                                        //* (e.g. "*.PIC") */
                     90:          lstrcpy(lpstrFilterSpec, "*");
                     91:          lstrcat(lpstrFilterSpec, szName);
                     92:          lpstrFilterSpec += lstrlen(lpstrFilterSpec) + 1;
                     93:       }
                     94:    }
                     95:    
                     96:    *lpstrFilterSpec = 0;
                     97: 
                     98:    return idFilterIndex;
                     99: 
                    100: }
                    101: 
                    102: 
                    103: 
                    104: /***************************************************************************
                    105:  *  RegCopyClassName()
                    106:  *
                    107:  *  Get the class name from the registration data base.  We have the
                    108:  *  descriptive name and we search for the class name.
                    109:  *
                    110:  *  returns BOOL - TRUE if class name was found and retrieved from the
                    111:  *                 registration database.
                    112:  ***************************************************************************/
                    113: 
                    114: BOOL FAR RegCopyClassName(             //* ENTRY:
                    115:    HWND           hwndList,            //* HANDLE to list box 
                    116:    LPSTR          lpstrClassName       //* destination character string
                    117: ){                                     //* LOCAL:
                    118:    DWORD          dwSize;              //* key name size
                    119:    HKEY           hkeyTemp;            //* temp key
                    120:    CHAR           szClass[KEYNAMESIZE];//* class name string
                    121:    CHAR           szKey[KEYNAMESIZE];  //* key name string
                    122:    INT            i;                   //* index
                    123: 
1.1.1.2 ! root      124:    szClass[0] = '\0';
1.1       root      125: 
                    126:    if (!RegOpenKey(HKEY_CLASSES_ROOT, szClass, &hkeyTemp)) 
                    127:    {
                    128:       i = (INT)SendMessage(hwndList, LB_GETCURSEL, 0, 0L);
                    129:       SendMessage(hwndList, LB_GETTEXT, i, (DWORD)(LPSTR)szKey);
                    130: 
                    131:       for (i = 0; !RegEnumKey(HKEY_CLASSES_ROOT, i++, szClass, KEYNAMESIZE); )
                    132:          if (*szClass != '.') 
                    133:          {
                    134:             dwSize = KEYNAMESIZE;
                    135:             if (!RegQueryValue(HKEY_CLASSES_ROOT, szClass, lpstrClassName, &dwSize))
                    136:                if (!lstrcmp(lpstrClassName, szKey))
                    137:                {
                    138:                     RegCloseKey(hkeyTemp);
                    139:                     lstrcpy(lpstrClassName,szClass);    
                    140:                     return TRUE;
                    141:                 }
                    142:          }
                    143:       RegCloseKey(hkeyTemp);
                    144:    }
                    145: 
1.1.1.2 ! root      146:    *lpstrClassName = 0;
1.1       root      147:    return FALSE;
                    148: 
                    149: }
                    150: 
                    151: 
                    152: 
                    153: /***************************************************************************
                    154:  *  RegGetClassNames()
                    155:  *
                    156:  *  Fills in the list box in the Insert New dialog with the names of 
                    157:  *  OLE Servers.
                    158:  *
                    159:  *  returns TRUE if the listbox filled successfully.
                    160:  **************************************************************************/
                    161: 
                    162: BOOL FAR RegGetClassNames(       //* ENTRY:
                    163:    HWND hwndList                 //* HANDLE to the listbox being filled
                    164: ){                               //* LOCAL:
                    165:    DWORD    dwSize;              //* sixe of data
                    166:    HKEY     hkeyTemp;            //* temporary registration key
                    167:    CHAR     szExec[KEYNAMESIZE]; //* executables name 
                    168:    CHAR     szClass[KEYNAMESIZE];//* class name
                    169:    CHAR     szName[KEYNAMESIZE]; //* key name
                    170:    INT      i;                   
                    171: 
                    172:    SendMessage(hwndList, LB_RESETCONTENT, 0, 0L);
                    173: 
1.1.1.2 ! root      174:    szClass[0]='\0';
1.1       root      175: 
                    176:    if (!RegOpenKey(HKEY_CLASSES_ROOT, szClass, &hkeyTemp)) 
                    177:    {
                    178:       for (i = 0; !RegEnumKey(HKEY_CLASSES_ROOT, i++, szClass, KEYNAMESIZE); )
                    179:          if (*szClass != '.') 
                    180:          {         
                    181:             lstrcpy(szExec, szClass);
                    182:             lstrcat(szExec, "\\protocol\\StdFileEditing\\server");
                    183:             dwSize = KEYNAMESIZE;
                    184:             if (!RegQueryValue(HKEY_CLASSES_ROOT, szExec, szName, &dwSize)) 
                    185:             {
                    186:                dwSize = KEYNAMESIZE;
                    187:                if (!RegQueryValue(HKEY_CLASSES_ROOT, szClass, szName, &dwSize)) 
                    188:                   SendMessage(hwndList, LB_ADDSTRING, 0, (DWORD)(LPSTR)szName);
                    189:             }
                    190:          }
                    191:       RegCloseKey(hkeyTemp);
                    192:       return TRUE;
                    193:    }
                    194:    return FALSE;
                    195: 
                    196: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.