2 * Win32 kernel functions
4 * Copyright 1995 Martin von Loewis and Cameron Heide
22 /* The global error value
26 /*********************************************************************
27 * CloseHandle (KERNEL32.23)
29 BOOL
CloseHandle(KERNEL_OBJECT
*handle
)
31 if (handle
<0x1000) /* FIXME: hack */
32 return CloseFileHandle(handle
);
33 if (handle
==0xFFFFFFFF)
37 case KERNEL_OBJECT_UNUSED
:
38 SetLastError(ERROR_INVALID_HANDLE
);
41 case KERNEL_OBJECT_FILE:
42 rc = CloseFileHandle((FILE_OBJECT *)handle);
47 dprintf_win32(stddeb
, "CloseHandle: type %ld not implemented yet.\n",
52 ReleaseKernelObject(handle
);
56 /***********************************************************************
57 * GetModuleHandle (KERNEL32.237)
59 HMODULE32
WIN32_GetModuleHandleA(char *module
)
63 dprintf_win32(stddeb
, "GetModuleHandleA: %s\n", module
? module
: "NULL");
64 /* Freecell uses the result of GetModuleHandleA(0) as the hInstance in
65 all calls to e.g. CreateWindowEx. */
67 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
68 hModule
= pTask
->hInstance
;
70 hModule
= GetModuleHandle(module
);
71 dprintf_win32(stddeb
, "GetModuleHandleA: returning %d\n", hModule
);
75 HMODULE32
WIN32_GetModuleHandleW(LPCWSTR module
)
79 if(module
==NULL
) return WIN32_GetModuleHandleA(NULL
);
80 modulea
=STRING32_DupUniToAnsi(module
);
81 hModule
= WIN32_GetModuleHandleA(modulea
);
87 /***********************************************************************
88 * GetStartupInfoA (KERNEL32.273)
90 VOID
GetStartupInfo32A(LPSTARTUPINFO32A lpStartupInfo
)
92 lpStartupInfo
->cb
= sizeof(STARTUPINFO32A
);
93 lpStartupInfo
->lpReserved
= "<Reserved>";
94 lpStartupInfo
->lpDesktop
= "Desktop";
95 lpStartupInfo
->lpTitle
= "Title";
97 lpStartupInfo
->cbReserved2
= 0;
98 lpStartupInfo
->lpReserved2
= NULL
; /* must be NULL for VC runtime */
99 lpStartupInfo
->hStdInput
= (HANDLE32
)0;
100 lpStartupInfo
->hStdOutput
= (HANDLE32
)1;
101 lpStartupInfo
->hStdError
= (HANDLE32
)2;
104 /***********************************************************************
105 * GetStartupInfoW (KERNEL32.274)
107 VOID
GetStartupInfo32W(LPSTARTUPINFO32W lpStartupInfo
)
109 lpStartupInfo
->cb
= sizeof(STARTUPINFO32W
);
110 lpStartupInfo
->lpReserved
= STRING32_DupAnsiToUni("<Reserved>");
111 lpStartupInfo
->lpDesktop
= STRING32_DupAnsiToUni("Desktop");
112 lpStartupInfo
->lpTitle
= STRING32_DupAnsiToUni("Title");
114 lpStartupInfo
->cbReserved2
= 0;
115 lpStartupInfo
->lpReserved2
= NULL
; /* must be NULL for VC runtime */
116 lpStartupInfo
->hStdInput
= (HANDLE32
)0;
117 lpStartupInfo
->hStdOutput
= (HANDLE32
)1;
118 lpStartupInfo
->hStdError
= (HANDLE32
)2;
121 /***********************************************************************
122 * GetStartupInfoA (KERNEL32.284)
123 * FIXME: perhaps supply better values.
124 * add other architectures for WINELIB.
127 GetSystemInfo(LPSYSTEM_INFO si
) {
130 si
->u
.x
.wProcessorArchitecture
= PROCESSOR_ARCHITECTURE_INTEL
;
132 si
->dwPageSize
= 4096; /* 4K */
133 si
->lpMinimumApplicationAddress
= 0x40000000;
134 si
->lpMaximumApplicationAddress
= 0x80000000;
135 si
->dwActiveProcessorMask
= 1;
136 si
->dwNumberOfProcessors
= 1;
138 /* FIXME: perhaps check compilation defines ... */
139 si
->dwProcessorType
= PROCESSOR_INTEL_386
;
144 case 4: si
->dwProcessorType
= PROCESSOR_INTEL_486
;
146 case 5: si
->dwProcessorType
= PROCESSOR_INTEL_PENTIUM
;
149 default: si
->dwProcessorType
= PROCESSOR_INTEL_386
;
153 si
->dwAllocationGranularity
= 8; /* hmm? */
154 si
->wProcessorLevel
= cpu
;
155 si
->wProcessorRevision
= 0; /* FIXME, see SDK */
158 /* Initialize whatever internal data structures we need.
160 * Returns 1 on success, 0 on failure.
162 int KERN32_Init(void)
165 /* Initialize exception handling */
171 /***********************************************************************
172 * GetComputerNameA (KERNEL32.165)
175 GetComputerName32A(LPSTR name
,LPDWORD size
) {
176 if (-1==gethostname(name
,*size
))
178 *size
= lstrlen32A(name
);
182 /***********************************************************************
183 * GetComputerNameW (KERNEL32.166)
186 GetComputerName32W(LPWSTR name
,LPDWORD size
) {
187 LPSTR nameA
= (LPSTR
)xmalloc(*size
);
189 if (!GetComputerName32A(nameA
,size
)) {
193 lstrcpynAtoW(name
,nameA
,*size
);
195 /* FIXME : size correct? */
199 /***********************************************************************
200 * GetUserNameA [ADVAPI32.67]
202 BOOL32
GetUserName32A(LPSTR lpszName
, LPDWORD lpSize
)
208 len
= name
? strlen(name
) : 0;
209 if (!len
|| !lpSize
|| len
> *lpSize
) {
210 if (lpszName
) *lpszName
= 0;
214 strcpy(lpszName
, name
);
218 /***********************************************************************
219 * GetUserNameW [ADVAPI32.68]
221 BOOL32
GetUserName32W(LPWSTR lpszName
, LPDWORD lpSize
)
223 LPSTR name
= (LPSTR
)xmalloc(*lpSize
);
224 DWORD size
= *lpSize
;
225 BOOL32 res
= GetUserName32A(name
,lpSize
);
227 lstrcpynAtoW(lpszName
,name
,size
);