2 * Win32 kernel functions
4 * Copyright 1995 Martin von Loewis and Cameron Heide
20 /* The global error value
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)
35 case KERNEL_OBJECT_UNUSED
:
36 SetLastError(ERROR_INVALID_HANDLE
);
39 case KERNEL_OBJECT_FILE:
40 rc = CloseFileHandle((FILE_OBJECT *)handle);
45 dprintf_win32(stddeb
, "CloseHandle: type %ld not implemented yet.\n",
50 ReleaseKernelObject(handle
);
54 /***********************************************************************
55 * GetModuleHandle (KERNEL32.237)
57 HMODULE32
WIN32_GetModuleHandleA(char *module
)
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. */
65 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
66 hModule
= pTask
->hInstance
;
68 hModule
= GetModuleHandle(module
);
69 dprintf_win32(stddeb
, "GetModuleHandleA: returning %d\n", hModule
);
73 HMODULE32
WIN32_GetModuleHandleW(LPCWSTR module
)
76 LPSTR modulea
= HEAP_strdupWtoA( GetProcessHeap(), 0, module
);
77 hModule
= WIN32_GetModuleHandleA( modulea
);
78 HeapFree( GetProcessHeap(), 0, modulea
);
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.
123 GetSystemInfo(LPSYSTEM_INFO si
) {
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;
134 /* FIXME: perhaps check compilation defines ... */
135 si
->dwProcessorType
= PROCESSOR_INTEL_386
;
140 case 4: si
->dwProcessorType
= PROCESSOR_INTEL_486
;
142 case 5: si
->dwProcessorType
= PROCESSOR_INTEL_PENTIUM
;
145 default: si
->dwProcessorType
= PROCESSOR_INTEL_386
;
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)
161 /* Initialize exception handling */
167 /***********************************************************************
168 * GetComputerNameA (KERNEL32.165)
171 GetComputerName32A(LPSTR name
,LPDWORD size
) {
172 if (-1==gethostname(name
,*size
))
174 *size
= lstrlen32A(name
);
178 /***********************************************************************
179 * GetComputerNameW (KERNEL32.166)
182 GetComputerName32W(LPWSTR name
,LPDWORD size
) {
183 LPSTR nameA
= (LPSTR
)xmalloc(*size
);
185 if (!GetComputerName32A(nameA
,size
)) {
189 lstrcpynAtoW(name
,nameA
,*size
);
191 /* FIXME : size correct? */
195 /***********************************************************************
196 * GetUserNameA [ADVAPI32.67]
198 BOOL32
GetUserName32A(LPSTR lpszName
, LPDWORD lpSize
)
204 len
= name
? strlen(name
) : 0;
205 if (!len
|| !lpSize
|| len
> *lpSize
) {
206 if (lpszName
) *lpszName
= 0;
210 strcpy(lpszName
, name
);
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
);