Release 961222
[wine/gsoc-2012-control.git] / win32 / init.c
blob3eb9ed32a2342968e8cac5517679209a46ba33db
1 /*
2 * Win32 kernel functions
4 * Copyright 1995 Martin von Loewis and Cameron Heide
5 */
7 #include <string.h>
8 #include <stdio.h>
9 #include <unistd.h>
10 #include "windows.h"
11 #include "winerror.h"
12 #include "handle32.h"
13 #include "except.h"
14 #include "heap.h"
15 #include "task.h"
16 #include "stddebug.h"
17 #include "debug.h"
18 #include "xmalloc.h"
20 /* The global error value
22 int WIN32_LastError;
24 /*********************************************************************
25 * CloseHandle (KERNEL32.23)
27 BOOL CloseHandle(KERNEL_OBJECT *handle)
29 if ((int)handle<0x1000) /* FIXME: hack */
30 return CloseFileHandle((int)handle);
31 if ((int)handle==0xFFFFFFFF)
32 return FALSE;
33 switch(handle->magic)
35 case KERNEL_OBJECT_UNUSED:
36 SetLastError(ERROR_INVALID_HANDLE);
37 return 0;
38 /* FIXME
39 case KERNEL_OBJECT_FILE:
40 rc = CloseFileHandle((FILE_OBJECT *)handle);
41 break;
44 default:
45 dprintf_win32(stddeb, "CloseHandle: type %ld not implemented yet.\n",
46 handle->magic);
47 break;
50 ReleaseKernelObject(handle);
51 return 0;
54 /***********************************************************************
55 * GetModuleHandle (KERNEL32.237)
57 HMODULE32 WIN32_GetModuleHandleA(char *module)
59 HMODULE32 hModule;
61 dprintf_win32(stddeb, "GetModuleHandleA: %s\n", module ? module : "NULL");
62 /* Freecell uses the result of GetModuleHandleA(0) as the hInstance in
63 all calls to e.g. CreateWindowEx. */
64 if (module == NULL) {
65 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
66 hModule = pTask->hInstance;
67 } else
68 hModule = GetModuleHandle(module);
69 dprintf_win32(stddeb, "GetModuleHandleA: returning %d\n", hModule );
70 return hModule;
73 HMODULE32 WIN32_GetModuleHandleW(LPCWSTR module)
75 HMODULE32 hModule;
76 LPSTR modulea = HEAP_strdupWtoA( GetProcessHeap(), 0, module );
77 hModule = WIN32_GetModuleHandleA( modulea );
78 HeapFree( GetProcessHeap(), 0, modulea );
79 return hModule;
83 /***********************************************************************
84 * GetStartupInfoA (KERNEL32.273)
86 VOID GetStartupInfo32A(LPSTARTUPINFO32A lpStartupInfo)
88 lpStartupInfo->cb = sizeof(STARTUPINFO32A);
89 lpStartupInfo->lpReserved = "<Reserved>";
90 lpStartupInfo->lpDesktop = "Desktop";
91 lpStartupInfo->lpTitle = "Title";
93 lpStartupInfo->cbReserved2 = 0;
94 lpStartupInfo->lpReserved2 = NULL; /* must be NULL for VC runtime */
95 lpStartupInfo->hStdInput = (HANDLE32)0;
96 lpStartupInfo->hStdOutput = (HANDLE32)1;
97 lpStartupInfo->hStdError = (HANDLE32)2;
100 /***********************************************************************
101 * GetStartupInfoW (KERNEL32.274)
103 VOID GetStartupInfo32W(LPSTARTUPINFO32W lpStartupInfo)
105 lpStartupInfo->cb = sizeof(STARTUPINFO32W);
106 lpStartupInfo->lpReserved = HEAP_strdupAtoW(GetProcessHeap(),0,"<Reserved>");
107 lpStartupInfo->lpDesktop = HEAP_strdupAtoW(GetProcessHeap(), 0, "Desktop");
108 lpStartupInfo->lpTitle = HEAP_strdupAtoW(GetProcessHeap(), 0, "Title");
110 lpStartupInfo->cbReserved2 = 0;
111 lpStartupInfo->lpReserved2 = NULL; /* must be NULL for VC runtime */
112 lpStartupInfo->hStdInput = (HANDLE32)0;
113 lpStartupInfo->hStdOutput = (HANDLE32)1;
114 lpStartupInfo->hStdError = (HANDLE32)2;
117 /***********************************************************************
118 * GetStartupInfoA (KERNEL32.284)
119 * FIXME: perhaps supply better values.
120 * add other architectures for WINELIB.
122 VOID
123 GetSystemInfo(LPSYSTEM_INFO si) {
124 WORD cpu;
126 si->u.x.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_INTEL;
128 si->dwPageSize = 4096; /* 4K */
129 si->lpMinimumApplicationAddress = (void *)0x40000000;
130 si->lpMaximumApplicationAddress = (void *)0x80000000;
131 si->dwActiveProcessorMask = 1;
132 si->dwNumberOfProcessors = 1;
133 #ifdef WINELIB
134 /* FIXME: perhaps check compilation defines ... */
135 si->dwProcessorType = PROCESSOR_INTEL_386;
136 cpu = 3;
137 #else
138 cpu = runtime_cpu();
139 switch (cpu) {
140 case 4: si->dwProcessorType = PROCESSOR_INTEL_486;
141 break;
142 case 5: si->dwProcessorType = PROCESSOR_INTEL_PENTIUM;
143 break;
144 case 3:
145 default: si->dwProcessorType = PROCESSOR_INTEL_386;
146 break;
148 #endif
149 si->dwAllocationGranularity = 8; /* hmm? */
150 si->wProcessorLevel = cpu;
151 si->wProcessorRevision = 0; /* FIXME, see SDK */
154 /* Initialize whatever internal data structures we need.
156 * Returns 1 on success, 0 on failure.
158 int KERN32_Init(void)
160 #ifndef WINELIB
161 /* Initialize exception handling */
162 EXC_Init();
163 #endif
164 return 1;
167 /***********************************************************************
168 * GetComputerNameA (KERNEL32.165)
170 BOOL32
171 GetComputerName32A(LPSTR name,LPDWORD size) {
172 if (-1==gethostname(name,*size))
173 return FALSE;
174 *size = lstrlen32A(name);
175 return TRUE;
178 /***********************************************************************
179 * GetComputerNameW (KERNEL32.166)
181 BOOL32
182 GetComputerName32W(LPWSTR name,LPDWORD size) {
183 LPSTR nameA = (LPSTR)xmalloc(*size);
185 if (!GetComputerName32A(nameA,size)) {
186 free(nameA);
187 return FALSE;
189 lstrcpynAtoW(name,nameA,*size);
190 free(nameA);
191 /* FIXME : size correct? */
192 return TRUE;
195 /***********************************************************************
196 * GetUserNameA [ADVAPI32.67]
198 BOOL32 GetUserName32A(LPSTR lpszName, LPDWORD lpSize)
200 size_t len;
201 char *name;
203 name=getlogin();
204 len = name ? strlen(name) : 0;
205 if (!len || !lpSize || len > *lpSize) {
206 if (lpszName) *lpszName = 0;
207 return 0;
209 *lpSize=len;
210 strcpy(lpszName, name);
211 return 1;
214 /***********************************************************************
215 * GetUserNameW [ADVAPI32.68]
217 BOOL32 GetUserName32W(LPWSTR lpszName, LPDWORD lpSize)
219 LPSTR name = (LPSTR)xmalloc(*lpSize);
220 DWORD size = *lpSize;
221 BOOL32 res = GetUserName32A(name,lpSize);
223 lstrcpynAtoW(lpszName,name,size);
224 return res;