|
|
1.1 root 1: /*
2: * REGDB.C
3: *
4: * Functions to query the registration database
5: *
6: * OleStdGetMiscStatusOfClass
7: * OleStdGetDefaultFileFormatOfClass
8: *
9: * NOTE: more regdb functions are in geticon.c --
10: * OleStdGetAuxUserType
11: * OleStdGetUserTypeOfClass
12: *
13: * (c) Copyright Microsoft Corp. 1992-1993 All Rights Reserved
14: *
15: */
16:
17: #define STRICT 1
18: #include "ole2ui.h"
19: #include <ctype.h>
20:
21: OLEDBGDATA
22:
23:
24: // Replacement for stdlib atol,
25: // which didn't work and doesn't take far pointers.
26: // Must be tolerant of leading spaces.
27: //
28: //
29: static LONG Atol(LPSTR lpsz)
30: {
31: signed int sign = +1;
32: UINT base = 10;
33: LONG l = 0;
34:
35: if (NULL==lpsz)
36: {
37: OleDbgAssert (0);
38: return 0;
39: }
40: while (isspace(*lpsz))
41: lpsz++;
42:
43: if (*lpsz=='-')
44: {
45: lpsz++;
46: sign = -1;
47: }
48: if (lpsz[0]=='0' && lpsz[1]=='x')
49: {
50: base = 16;
51: lpsz+=2;
52: }
53:
54: if (base==10)
55: {
56: while (isdigit(*lpsz))
57: {
58: l = l * base + *lpsz - '0';
59: lpsz++;
60: }
61: }
62: else
63: {
64: OleDbgAssert (base==16);
65: while (isxdigit(*lpsz))
66: {
67: l = l * base + isdigit(*lpsz) ? *lpsz - '0' : toupper(*lpsz) - 'A' + 10;
68: lpsz++;
69: }
70: }
71: return l * sign;
72: }
73:
74:
75:
76:
77: /*
78: * OleStdGetMiscStatusOfClass(REFCLSID, HKEY)
79: *
80: * Purpose:
81: * Returns the value of the misc status for the given clsid.
82: *
83: * Parameters:
84: * rclsid pointer to the clsid to retrieve user type of.
85: * hKey hKey for reg db - if this is NULL, then we
86: * open and close the reg db within this function. If it
87: * is non-NULL, then we assume it's a valid key to the
88: * \\CLSID root and use it without closing it. (useful
89: * if you're doing lots of reg db stuff).
90: *
91: * Return Value:
92: * BOOL TRUE on success, FALSE on failure.
93: *
94: */
95: STDAPI_(BOOL) OleStdGetMiscStatusOfClass(REFCLSID rclsid, HKEY hKey, DWORD FAR * lpdwValue)
96: {
97: DWORD dw;
98: LONG lRet;
99: LPSTR lpszCLSID;
100: char szKey[64];
101: char szMiscStatus[OLEUI_CCHKEYMAX];
102: BOOL bCloseRegDB = FALSE;
103:
104: if (hKey == NULL)
105: {
106:
107: //Open up the root key.
108: lRet=RegOpenKey(HKEY_CLASSES_ROOT, "CLSID", &hKey);
109:
110: if ((LONG)ERROR_SUCCESS!=lRet)
111: return FALSE;
112:
113: bCloseRegDB = TRUE;
114: }
115:
116: // Get a string containing the class name
117: StringFromCLSID(rclsid, &lpszCLSID);
118:
119: // Construct key
120: lstrcpy(szKey, lpszCLSID);
121: lstrcat(szKey, "\\MiscStatus");
122:
123:
124: dw=OLEUI_CCHKEYMAX;
125: lRet = RegQueryValue(hKey, szKey, (LPSTR)szMiscStatus, &dw);
126:
127: if ((LONG)ERROR_SUCCESS!=lRet)
128: {
129: OleStdFreeString(lpszCLSID, NULL);
130:
131: if (bCloseRegDB)
132: RegCloseKey(hKey);
133:
134: return FALSE;
135:
136: }
137:
138: *lpdwValue = Atol((LPSTR)szMiscStatus);
139:
140: OleStdFreeString(lpszCLSID, NULL);
141:
142: if (bCloseRegDB)
143: RegCloseKey(hKey);
144:
145: return TRUE;
146:
147:
148: }
149:
150:
151: /*
152: * CLIPFORMAT OleStdGetDefaultFileFormatOfClass(REFCLSID, HKEY)
153: *
154: * Purpose:
155: * Returns the default file format of the specified class.
156: * this is entered in REGDB as follows:
157: * CLSID\{...}\DataFormats\DefaultFile = <cfFmt>
158: *
159: * Parameters:
160: * rclsid pointer to the clsid to retrieve user type of.
161: * hKey hKey for reg db- if this is NULL, then we
162: * open and close the reg db within this function. If it
163: * is non-NULL, then we assume it's a valid key to the
164: * \ root and use it without closing it. (useful
165: * if you're doing lots of reg db stuff).
166: *
167: * Return Value:
168: * cfFmt -- DefaultFile format
169: * NULL -- failed to get default file format
170: *
171: */
172: STDAPI_(CLIPFORMAT) OleStdGetDefaultFileFormatOfClass(
173: REFCLSID rclsid,
174: HKEY hKey
175: )
176: {
177: CLIPFORMAT cfFmt = 0;
178: DWORD dw;
179: LONG lRet;
180: LPSTR lpszCLSID;
181: BOOL bCloseRegDB = FALSE;
182: char szKey[128];
183: char szDefaultFile[OLEUI_CCHKEYMAX];
184: BOOL bStatus = TRUE;
185:
186:
187: if (hKey == NULL)
188: {
189:
190: //Open up the root key.
191: lRet=RegOpenKey(HKEY_CLASSES_ROOT, NULL, &hKey);
192:
193: if ((LONG)ERROR_SUCCESS!=lRet)
194: return 0;
195:
196: bCloseRegDB = TRUE;
197: }
198:
199:
200: // Get a string containing the class name
201: StringFromCLSID(rclsid, &lpszCLSID);
202:
203: // Construct key
204: wsprintf(szKey, "CLSID\\%s\\DataFormats\\DefaultFile", lpszCLSID);
205:
206: dw=OLEUI_CCHKEYMAX;
207: lRet = RegQueryValue(hKey, szKey, (LPSTR)szDefaultFile, (LONG FAR *)&dw);
208:
209: if ((LONG)ERROR_SUCCESS!=lRet)
210: bStatus = FALSE;
211: else {
212: /* if the format is a number, then it should refer to one of the
213: ** standard Windows formats.
214: */
215: if (isdigit(szDefaultFile[0]))
216: cfFmt = (CLIPFORMAT)Atol(szDefaultFile);
217: else
218: cfFmt = RegisterClipboardFormat(szDefaultFile);
219: }
220:
221: if (bCloseRegDB)
222: RegCloseKey(hKey);
223:
224: return cfFmt;
225: }
226:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.