2 * Shell Library Functions
12 #include "../rc/sysres.h"
14 /* #define DEBUG_REG */
17 LPKEYSTRUCT lphRootKey
= NULL
;
19 /*************************************************************************
20 * RegOpenKey [SHELL.1]
22 LONG
RegOpenKey(HKEY hKey
, LPCSTR lpSubKey
, HKEY FAR
*lphKey
)
24 LPKEYSTRUCT lpKey
= lphRootKey
;
28 dprintf_reg(stddeb
, "RegOpenKey(%08lX, %p='%s', %p)\n",
29 hKey
, lpSubKey
, lpSubKey
, lphKey
);
30 if (lpKey
== NULL
) return ERROR_BADKEY
;
31 if (lpSubKey
== NULL
) return ERROR_INVALID_PARAMETER
;
32 if (lphKey
== NULL
) return ERROR_INVALID_PARAMETER
;
33 if (hKey
!= HKEY_CLASSES_ROOT
) {
34 dprintf_reg(stddeb
,"RegOpenKey // specific key = %08lX !\n", hKey
);
35 lpKey
= (LPKEYSTRUCT
)GlobalLock(hKey
);
37 while ( (ptr
= strchr(lpSubKey
, '\\')) != NULL
) {
38 strncpy(str
, lpSubKey
, (LONG
)ptr
- (LONG
)lpSubKey
);
39 str
[(LONG
)ptr
- (LONG
)lpSubKey
] = '\0';
41 dprintf_reg(stddeb
,"RegOpenKey // next level '%s' !\n", str
);
43 dprintf_reg(stddeb
,"RegOpenKey // '%s' <-> '%s' !\n", str
, lpKey
->lpSubKey
);
44 if (lpKey
->lpSubKey
!= NULL
&& lpKey
->lpSubKey
[0] != '\0' &&
45 strcmp(lpKey
->lpSubKey
, str
) == 0) {
46 lpKey
= lpKey
->lpSubLvl
;
48 printf("RegOpenKey // can't find subkey '%s' !\n", str
);
53 if (lpKey
->lpNextKey
== NULL
) {
54 printf("RegOpenKey // can't find subkey '%s' !\n", str
);
57 lpKey
= lpKey
->lpNextKey
;
61 if (lpKey
->lpSubKey
!= NULL
&&
62 strcmp(lpKey
->lpSubKey
, lpSubKey
) == 0) break;
63 if (lpKey
->lpNextKey
== NULL
) {
64 printf("RegOpenKey // can't find subkey '%s' !\n", str
);
67 lpKey
= lpKey
->lpNextKey
;
69 *lphKey
= lpKey
->hKey
;
70 dprintf_reg(stddeb
,"RegOpenKey // return hKey=%08lX !\n", lpKey
->hKey
);
75 /*************************************************************************
76 * RegCreateKey [SHELL.2]
78 LONG
RegCreateKey(HKEY hKey
, LPCSTR lpSubKey
, HKEY FAR
*lphKey
)
82 LPKEYSTRUCT lpKey
= lphRootKey
;
83 LPKEYSTRUCT lpPrevKey
;
87 dprintf_reg(stddeb
, "RegCreateKey(%08lX, '%s', %p)\n", hKey
, lpSubKey
, lphKey
);
88 if (lpSubKey
== NULL
) return ERROR_INVALID_PARAMETER
;
89 if (lphKey
== NULL
) return ERROR_INVALID_PARAMETER
;
90 if (hKey
!= HKEY_CLASSES_ROOT
) {
91 dprintf_reg(stddeb
,"RegCreateKey // specific key = %08lX !\n", hKey
);
92 lpKey
= (LPKEYSTRUCT
)GlobalLock(hKey
);
94 while ( (ptr
= strchr(lpSubKey
, '\\')) != NULL
) {
95 strncpy(str
, lpSubKey
, (LONG
)ptr
- (LONG
)lpSubKey
);
96 str
[(LONG
)ptr
- (LONG
)lpSubKey
] = '\0';
98 dprintf_reg(stddeb
,"RegCreateKey // next level '%s' !\n", str
);
101 dprintf_reg(stddeb
,"RegCreateKey // '%s' <-> '%s' !\n", str
, lpKey
->lpSubKey
);
102 if (lpKey
->lpSubKey
!= NULL
&&
103 strcmp(lpKey
->lpSubKey
, str
) == 0) {
104 if (lpKey
->lpSubLvl
== NULL
) {
105 dprintf_reg(stddeb
,"RegCreateKey // '%s' found !\n", str
);
106 if ( (ptr
= strchr(lpSubKey
, '\\')) != NULL
) {
107 strncpy(str
, lpSubKey
, (LONG
)ptr
- (LONG
)lpSubKey
);
108 str
[(LONG
)ptr
- (LONG
)lpSubKey
] = '\0';
112 strcpy(str
, lpSubKey
);
113 dwRet
= RegCreateKey(lpKey
->hKey
, str
, &hNewKey
);
114 if (dwRet
!= ERROR_SUCCESS
) {
115 printf("RegCreateKey // can't create subkey '%s' !\n", str
);
118 lpKey
->lpSubLvl
= (LPKEYSTRUCT
)GlobalLock(hNewKey
);
120 lpKey
= lpKey
->lpSubLvl
;
123 if (lpKey
->lpNextKey
== NULL
) {
124 dwRet
= RegCreateKey(lpPrevKey
->hKey
, str
, &hNewKey
);
125 if (dwRet
!= ERROR_SUCCESS
) {
126 printf("RegCreateKey // can't create subkey '%s' !\n", str
);
129 lpKey
= (LPKEYSTRUCT
)GlobalLock(hNewKey
);
132 lpKey
= lpKey
->lpNextKey
;
135 hNewKey
= GlobalAlloc(GMEM_MOVEABLE
, sizeof(KEYSTRUCT
));
136 lpNewKey
= (LPKEYSTRUCT
) GlobalLock(hNewKey
);
137 if (lpNewKey
== NULL
) {
138 printf("RegCreateKey // Can't alloc new key !\n");
139 return ERROR_OUTOFMEMORY
;
141 if (lphRootKey
== NULL
) {
142 lphRootKey
= lpNewKey
;
143 lpNewKey
->lpPrevKey
= NULL
;
146 lpKey
->lpNextKey
= lpNewKey
;
147 lpNewKey
->lpPrevKey
= lpKey
;
149 lpNewKey
->hKey
= hNewKey
;
150 lpNewKey
->lpSubKey
= malloc(strlen(lpSubKey
) + 1);
151 if (lpNewKey
->lpSubKey
== NULL
) {
152 printf("RegCreateKey // Can't alloc key string !\n");
153 return ERROR_OUTOFMEMORY
;
155 strcpy(lpNewKey
->lpSubKey
, lpSubKey
);
156 lpNewKey
->dwType
= 0;
157 lpNewKey
->lpValue
= NULL
;
158 lpNewKey
->lpNextKey
= NULL
;
159 lpNewKey
->lpSubLvl
= NULL
;
161 dprintf_reg(stddeb
,"RegCreateKey // successful '%s' key=%08lX !\n", lpSubKey
, hNewKey
);
162 return ERROR_SUCCESS
;
166 /*************************************************************************
167 * RegCloseKey [SHELL.3]
169 LONG
RegCloseKey(HKEY hKey
)
171 dprintf_reg(stdnimp
, "EMPTY STUB !!! RegCloseKey(%08lX);\n", hKey
);
172 return ERROR_INVALID_PARAMETER
;
176 /*************************************************************************
177 * RegDeleteKey [SHELL.4]
179 LONG
RegDeleteKey(HKEY hKey
, LPCSTR lpSubKey
)
181 dprintf_reg(stdnimp
, "EMPTY STUB !!! RegDeleteKey(%08lX, '%s');\n",
183 return ERROR_INVALID_PARAMETER
;
187 /*************************************************************************
188 * RegSetValue [SHELL.5]
190 LONG
RegSetValue(HKEY hKey
, LPCSTR lpSubKey
, DWORD dwType
,
191 LPCSTR lpVal
, DWORD dwIgnored
)
196 dprintf_reg(stddeb
, "RegSetValue(%08lX, '%s', %08lX, '%s', %08lX);\n",
197 hKey
, lpSubKey
, dwType
, lpVal
, dwIgnored
);
198 if (lpSubKey
== NULL
) return ERROR_INVALID_PARAMETER
;
199 if (lpVal
== NULL
) return ERROR_INVALID_PARAMETER
;
200 if ((dwRet
= RegOpenKey(hKey
, lpSubKey
, &hRetKey
)) != ERROR_SUCCESS
) {
201 dprintf_reg(stddeb
, "RegSetValue // key not found ... so create it !\n");
202 if ((dwRet
= RegCreateKey(hKey
, lpSubKey
, &hRetKey
)) != ERROR_SUCCESS
) {
203 fprintf(stderr
, "RegSetValue // key creation error %08lX !\n", dwRet
);
207 lpKey
= (LPKEYSTRUCT
)GlobalLock(hRetKey
);
208 if (lpKey
== NULL
) return ERROR_BADKEY
;
209 if (lpKey
->lpValue
!= NULL
) free(lpKey
->lpValue
);
210 lpKey
->lpValue
= malloc(strlen(lpVal
) + 1);
211 strcpy(lpKey
->lpValue
, lpVal
);
212 dprintf_reg(stddeb
,"RegSetValue // successful key='%s' val='%s' !\n", lpSubKey
, lpVal
);
213 return ERROR_SUCCESS
;
217 /*************************************************************************
218 * RegQueryValue [SHELL.6]
220 LONG
RegQueryValue(HKEY hKey
, LPCSTR lpSubKey
, LPSTR lpVal
, LONG FAR
*lpcb
)
226 dprintf_reg(stddeb
, "RegQueryValue(%08lX, '%s', %p, %p);\n",
227 hKey
, lpSubKey
, lpVal
, lpcb
);
228 if (lpSubKey
== NULL
) return ERROR_INVALID_PARAMETER
;
229 if (lpVal
== NULL
) return ERROR_INVALID_PARAMETER
;
230 if (lpcb
== NULL
) return ERROR_INVALID_PARAMETER
;
231 if ((dwRet
= RegOpenKey(hKey
, lpSubKey
, &hRetKey
)) != ERROR_SUCCESS
) {
232 fprintf(stderr
, "RegQueryValue // key not found !\n");
235 lpKey
= (LPKEYSTRUCT
)GlobalLock(hRetKey
);
236 if (lpKey
== NULL
) return ERROR_BADKEY
;
237 if (lpKey
->lpValue
!= NULL
) {
238 size
= min(strlen(lpKey
->lpValue
), *lpcb
);
239 strncpy(lpVal
, lpKey
->lpValue
, size
);
246 dprintf_reg(stddeb
,"RegQueryValue // return '%s' !\n", lpVal
);
247 return ERROR_SUCCESS
;
251 /*************************************************************************
252 * RegEnumKey [SHELL.7]
254 LONG
RegEnumKey(HKEY hKey
, DWORD dwSubKey
, LPSTR lpBuf
, DWORD dwSize
)
256 dprintf_reg(stdnimp
, "RegEnumKey : Empty Stub !!!\n");
257 return ERROR_INVALID_PARAMETER
;
260 /*************************************************************************
261 * DragAcceptFiles [SHELL.9]
263 void DragAcceptFiles(HWND hWnd
, BOOL b
)
265 dprintf_reg(stdnimp
, "DragAcceptFiles : Empty Stub !!!\n");
269 /*************************************************************************
270 * DragQueryFile [SHELL.11]
272 void DragQueryFile(HDROP h
, UINT u
, LPSTR u2
, UINT u3
)
274 dprintf_reg(stdnimp
, "DragQueryFile : Empty Stub !!!\n");
279 /*************************************************************************
280 * DragFinish [SHELL.12]
282 void DragFinish(HDROP h
)
284 dprintf_reg(stdnimp
, "DragFinish : Empty Stub !!!\n");
289 /*************************************************************************
290 * DragQueryPoint [SHELL.13]
292 BOOL
DragQueryPoint(HDROP h
, POINT FAR
*p
)
294 dprintf_reg(stdnimp
, "DragQueryPoinyt : Empty Stub !!!\n");
299 /*************************************************************************
300 * ShellExecute [SHELL.20]
302 HINSTANCE
ShellExecute(HWND hWnd
, LPCSTR lpOperation
, LPCSTR lpFile
, LPCSTR lpParameters
, LPCSTR lpDirectory
, int iShowCmd
)
304 dprintf_reg(stdnimp
, "ShellExecute // hWnd=%04X\n", hWnd
);
305 dprintf_reg(stdnimp
, "ShellExecute // lpOperation='%s'\n", lpOperation
);
306 dprintf_reg(stdnimp
, "ShellExecute // lpFile='%s'\n", lpFile
);
307 dprintf_reg(stdnimp
, "ShellExecute // lpParameters='%s'\n", lpParameters
);
308 dprintf_reg(stdnimp
, "ShellExecute // lpDirectory='%s'\n", lpDirectory
);
309 dprintf_reg(stdnimp
, "ShellExecute // iShowCmd=%04X\n", iShowCmd
);
310 return 2; /* file not found */
314 /*************************************************************************
315 * FindExecutable [SHELL.21]
317 HINSTANCE
FindExecutable(LPCSTR lpFile
, LPCSTR lpDirectory
, LPSTR lpResult
)
319 dprintf_reg(stdnimp
, "FindExecutable : Empty Stub !!!\n");
323 char AppName
[256], AppMisc
[256];
324 INT
AboutDlgProc(HWND hWnd
, WORD msg
, WORD wParam
, LONG lParam
);
326 /*************************************************************************
327 * ShellAbout [SHELL.22]
329 INT
ShellAbout(HWND hWnd
, LPCSTR szApp
, LPCSTR szOtherStuff
, HICON hIcon
)
331 /* fprintf(stderr, "ShellAbout ! (%s, %s)\n", szApp, szOtherStuff);*/
334 strcpy(AppName
, szApp
);
339 strcpy(AppMisc
, szOtherStuff
);
343 return DialogBoxIndirectPtr(hSysRes
, sysres_DIALOG_SHELL_ABOUT_MSGBOX
, hWnd
, (WNDPROC
)AboutDlgProc
);
347 /*************************************************************************
348 * AboutDlgProc [SHELL.33]
350 INT
AboutDlgProc(HWND hWnd
, WORD msg
, WORD wParam
, LONG lParam
)
356 sprintf(temp
, "About %s", AppName
);
357 SetWindowText(hWnd
, temp
);
358 SetDlgItemText(hWnd
, 100, AppMisc
);
364 EndDialog(hWnd
, TRUE
);
371 /*************************************************************************
372 * ExtractIcon [SHELL.34]
374 HICON
ExtractIcon(HINSTANCE hInst
, LPCSTR lpszExeFileName
, UINT nIconIndex
)
378 HINSTANCE hInst2
= hInst
;
379 dprintf_reg(stddeb
, "ExtractIcon(%04X, '%s', %d\n",
380 hInst
, lpszExeFileName
, nIconIndex
);
381 if (lpszExeFileName
!= NULL
) {
382 hInst2
= LoadLibrary(lpszExeFileName
);
384 if (hInst2
!= 0 && nIconIndex
== (UINT
)-1) {
385 count
= GetRsrcCount(hInst2
, NE_RSCTYPE_GROUP_ICON
);
386 dprintf_reg(stddeb
, "ExtractIcon // '%s' has %d icons !\n", lpszExeFileName
, count
);
389 if (hInst2
!= hInst
&& hInst2
!= 0) {
396 /*************************************************************************
397 * ExtractAssociatedIcon [SHELL.36]
399 HICON
ExtractAssociatedIcon(HINSTANCE hInst
,LPSTR lpIconPath
, LPWORD lpiIcon
)
401 dprintf_reg(stdnimp
, "ExtractAssociatedIcon : Empty Stub !!!\n");
405 /*************************************************************************
406 * RegisterShellHook [SHELL.102]
408 int RegisterShellHook(void *ptr
)
410 dprintf_reg(stdnimp
, "RegisterShellHook : Empty Stub !!!\n");
415 /*************************************************************************
416 * ShellHookProc [SHELL.103]
418 int ShellHookProc(void)
420 dprintf_reg(stdnimp
, "ShellHookProc : Empty Stub !!!\n");