Release 960506
[wine.git] / win32 / init.c
blob09578227e46e6eeb4987caed41475c56ae49b68c
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 "kernel32.h"
13 #include "handle32.h"
14 #include "except.h"
15 #include "task.h"
16 #include "stddebug.h"
17 #define DEBUG_WIN32
18 #include "debug.h"
20 /* The global error value
22 int WIN32_LastError;
24 /* Standard system handles for stdin, stdout, and stderr.
26 FILE_OBJECT *hstdin, *hstdout, *hstderr;
28 static int CreateStdHandles(void);
30 /*********************************************************************
31 * CloseHandle (KERNEL32.23)
33 BOOL CloseHandle(KERNEL_OBJECT *handle)
35 int rc;
37 if(ValidateKernelObject(handle) != 0)
39 SetLastError(ERROR_INVALID_HANDLE);
40 return 0;
43 switch(handle->magic)
45 case KERNEL_OBJECT_UNUSED:
46 SetLastError(ERROR_INVALID_HANDLE);
47 return 0;
49 case KERNEL_OBJECT_FILE:
50 rc = CloseFileHandle((FILE_OBJECT *)handle);
51 break;
53 default:
54 dprintf_win32(stddeb, "CloseHandle: type %ld not implemented yet.\n",
55 handle->magic);
56 break;
59 ReleaseKernelObject(handle);
60 return 0;
63 /***********************************************************************
64 * GetModuleFileNameA (KERNEL32.235)
66 DWORD GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize)
68 strcpy(lpFilename, "c:\\dummy");
69 return 8;
72 /***********************************************************************
73 * GetModuleHandle (KERNEL32.237)
75 HMODULE WIN32_GetModuleHandle(char *module)
77 HMODULE hModule;
79 dprintf_win32(stddeb, "GetModuleHandle: %s\n", module ? module : "NULL");
80 /* Freecell uses the result of GetModuleHandleA(0) as the hInstance in
81 all calls to e.g. CreateWindowEx. */
82 if (module == NULL) {
83 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
84 hModule = pTask->hInstance;
85 } else
86 hModule = GetModuleHandle(module);
87 dprintf_win32(stddeb, "GetModuleHandle: returning %d\n", hModule );
88 return hModule;
91 /***********************************************************************
92 * GetStartupInfoA (KERNEL32.273)
94 VOID GetStartupInfoA(LPSTARTUPINFO lpStartupInfo)
96 lpStartupInfo->cb = sizeof(STARTUPINFO);
97 lpStartupInfo->lpReserved = NULL;
98 lpStartupInfo->lpDesktop = "Desktop";
99 lpStartupInfo->lpTitle = "Title";
101 lpStartupInfo->cbReserved2 = 0;
102 lpStartupInfo->lpReserved2 = NULL; /* must be NULL for VC runtime */
103 lpStartupInfo->hStdInput = (HANDLE)0;
104 lpStartupInfo->hStdOutput = (HANDLE)1;
105 lpStartupInfo->hStdError = (HANDLE)2;
108 /* Initialize whatever internal data structures we need.
110 * Returns 1 on success, 0 on failure.
112 int KERN32_Init(void)
114 #ifndef WINELIB
115 /* Initialize exception handling */
116 EXC_Init();
117 #endif
119 /* Create the standard system handles
121 if(CreateStdHandles() != 0)
122 return 0;
124 return 1;
127 /* CreateStdHandles creates the standard input, output, and error handles.
128 * These handles aren't likely to be used since they're generally used for
129 * console output, but startup code still likes to mess with them. They're
130 * also useful for debugging since apps and runtime libraries might write
131 * errors to stderr.
133 * Returns 0 on success, nonzero on failure.
135 static int CreateStdHandles(void)
137 /* Create the standard input handle.
139 hstdin = (FILE_OBJECT *)CreateKernelObject(sizeof(FILE_OBJECT));
140 if(hstdin == NULL)
141 return 1;
142 hstdin->common.magic = KERNEL_OBJECT_FILE;
143 hstdin->fd = 0;
144 hstdin->type = FILE_TYPE_CHAR;
145 hstdin->misc_flags = 0;
147 /* Create the standard output handle
149 hstdout = (FILE_OBJECT *)CreateKernelObject(sizeof(FILE_OBJECT));
150 if(hstdout == NULL)
151 return 1;
152 hstdout->common.magic = KERNEL_OBJECT_FILE;
153 hstdout->fd = 1;
154 hstdout->type = FILE_TYPE_CHAR;
155 hstdout->misc_flags = 0;
157 /* Create the standard error handle
159 hstderr = (FILE_OBJECT *)CreateKernelObject(sizeof(FILE_OBJECT));
160 if(hstderr == NULL)
161 return 1;
162 hstderr->common.magic = KERNEL_OBJECT_FILE;
163 hstderr->fd = 2;
164 hstderr->type = FILE_TYPE_CHAR;
165 hstderr->misc_flags = 0;
167 return 0;