Some basics of driver wrapper - establish dispatch functions, a very basic AddDevice...
[reactos.git] / rosapps / control / control.c
1 /*
2 * Control
3 * Copyright (C) 1998 by Marcel Baur <mbaur@g26.ethz.ch>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 /*
20 * Portions copyright Robert Dickenson <robd@reactos.org>, August 15, 2002.
21 */
22
23 #define WIN32_LEAN_AND_MEAN
24 #include <windows.h>
25 #include <stdlib.h>
26 #include <tchar.h>
27 #include "params.h"
28
29 //typedef void (WINAPI *CONTROL_RUNDLL)(HWND hWnd, HINSTANCE hInst, LPCTSTR cmd, DWORD nCmdShow);
30 typedef void (*CONTROL_RUNDLL)(HWND hWnd, HINSTANCE hInst, LPCTSTR cmd, DWORD nCmdShow);
31
32 const TCHAR szLibName[] = _T("ROSHEL32.DLL");
33 #ifdef UNICODE
34 const char szProcName[] = "Control_RunDLLW";
35 #else
36 const char szProcName[] = "Control_RunDLLA";
37 #endif
38
39 #ifndef __GNUC__
40 #ifdef UNICODE
41 extern void __declspec(dllimport) Control_RunDLLW(HWND hWnd, HINSTANCE hInst, LPCWSTR cmd, DWORD nCmdShow);
42 #else
43 extern void __declspec(dllimport) Control_RunDLLA(HWND hWnd, HINSTANCE hInst, LPCSTR cmd, DWORD nCmdShow);
44 #endif
45 #endif
46
47 #ifdef UNICODE
48 #define Control_RunDLL Control_RunDLLW
49 #else
50 #define Control_RunDLL Control_RunDLLA
51 #endif
52
53
54 void launch(LPTSTR lpCmdLine)
55 {
56 #if 0
57 HMODULE hShell32;
58 CONTROL_RUNDLL pControl_RunDLL;
59
60 hShell32 = LoadLibrary(szLibName);
61 if (hShell32) {
62 pControl_RunDLL = (CONTROL_RUNDLL)(FARPROC)GetProcAddress(hShell32, szProcName);
63 if (pControl_RunDLL) {
64 pControl_RunDLL(GetDesktopWindow(), 0, lpCmdLine, SW_SHOW);
65 } else {
66 _tprintf(_T("ERROR: failed to Get Procedure Address for %s in Library %s\n"), szLibName, szProcName);
67 }
68 FreeLibrary(hShell32);
69 } else {
70 _tprintf(_T("ERROR: failed to Load Library %s\n"), szLibName);
71 }
72 #else
73 Control_RunDLL(GetDesktopWindow(), 0, lpCmdLine, SW_SHOW);
74 #endif
75 exit(0);
76 }
77
78 int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, CHAR *szParam, INT argc)
79 {
80 TCHAR szParams[255];
81 LPTSTR pParams = GetCommandLine();
82 lstrcpy(szParams, pParams);
83 CharUpper(szParams);
84
85 _tprintf(_T("Control Panel Launcher...\n"));
86
87 switch (--argc) {
88 case 0: /* no parameters - pop up whole "Control Panel" by default */
89 launch(_T(""));
90 break;
91 case 1: /* check for optional parameter */
92 if (!lstrcmp(szParams,szP_DESKTOP))
93 launch(szC_DESKTOP);
94 if (!lstrcmp(szParams,szP_COLOR))
95 launch(szC_COLOR);
96 if (!lstrcmp(szParams,szP_DATETIME))
97 launch(szC_DATETIME);
98 if (!lstrcmp(szParams,szP_DESKTOP))
99 launch(szC_DESKTOP);
100 if (!lstrcmp(szParams,szP_INTERNATIONAL))
101 launch(szC_INTERNATIONAL);
102 if (!lstrcmp(szParams,szP_KEYBOARD))
103 launch(szC_KEYBOARD);
104 if (!lstrcmp(szParams,szP_MOUSE))
105 launch(szC_MOUSE);
106 if (!lstrcmp(szParams,szP_PORTS))
107 launch(szC_PORTS);
108 if (!lstrcmp(szParams,szP_PRINTERS))
109 launch(szC_PRINTERS);
110 /* try to launch if a .cpl file is given directly */
111 launch(szParams);
112 break;
113 default: _tprintf(_T("Syntax error."));
114 }
115 return 0;
116 }