Release 951124
[wine/multimedia.git] / win32 / init.c
blobb4d3f0dfb837a0b520aae03feae680eafadf4ee1
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 "stddebug.h"
15 #include "debug.h"
17 /* The global error value
19 int WIN32_LastError;
21 /* Standard system handles for stdin, stdout, and stderr.
23 FILE_OBJECT *hstdin, *hstdout, *hstderr;
25 static int CreateStdHandles(void);
27 /*********************************************************************
28 * CloseHandle (KERNEL32.23)
30 BOOL CloseHandle(HANDLE32 handle)
32 int rc;
34 if(ValidateKernelObject(handle) != 0)
36 SetLastError(ERROR_INVALID_HANDLE);
37 return 0;
40 switch(handle->magic)
42 case KERNEL_OBJECT_UNUSED:
43 SetLastError(ERROR_INVALID_HANDLE);
44 return 0;
46 case KERNEL_OBJECT_FILE:
47 rc = CloseFileHandle((FILE_OBJECT *)handle);
48 break;
50 default:
51 printf("CloseHandle: type %ld not implemented yet.\n",
52 handle->magic);
53 break;
56 ReleaseKernelObject(handle);
57 return 0;
60 /***********************************************************************
61 * GetModuleFileNameA (KERNEL32.235)
63 DWORD GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize)
65 strcpy(lpFilename, "c:\\dummy");
66 return 8;
69 /***********************************************************************
70 * GetModuleHandle (KERNEL32.237)
72 HMODULE WIN32_GetModuleHandle(char *module)
74 if(module == NULL)
75 return (HMODULE)0;
76 else
77 return GetModuleHandle(module);
80 /***********************************************************************
81 * GetStartupInfoA (KERNEL32.273)
83 VOID GetStartupInfoA(LPSTARTUPINFO lpStartupInfo)
85 lpStartupInfo->cb = sizeof(STARTUPINFO);
86 lpStartupInfo->lpReserved = NULL;
87 lpStartupInfo->lpDesktop = "Desktop";
88 lpStartupInfo->lpTitle = "Title";
90 lpStartupInfo->lpReserved2 = NULL; /* must be NULL for VC runtime */
91 lpStartupInfo->hStdInput = (HANDLE)0;
92 lpStartupInfo->hStdOutput = (HANDLE)1;
93 lpStartupInfo->hStdError = (HANDLE)2;
96 /* Initialize whatever internal data structures we need.
98 * Returns 1 on success, 0 on failure.
100 int KERN32_Init(void)
102 /* Create the standard system handles
104 if(CreateStdHandles() != 0)
105 return 0;
107 return 1;
110 /* CreateStdHandles creates the standard input, output, and error handles.
111 * These handles aren't likely to be used since they're generally used for
112 * console output, but startup code still likes to mess with them. They're
113 * also useful for debugging since apps and runtime libraries might write
114 * errors to stderr.
116 * Returns 0 on success, nonzero on failure.
118 static int CreateStdHandles(void)
120 /* Create the standard input handle.
122 hstdin = (FILE_OBJECT *)CreateKernelObject(sizeof(FILE_OBJECT));
123 if(hstdin == NULL)
124 return 1;
125 hstdin->common.magic = KERNEL_OBJECT_FILE;
126 hstdin->fd = 0;
127 hstdin->type = FILE_TYPE_CHAR;
128 hstdin->misc_flags = 0;
130 /* Create the standard output handle
132 hstdout = (FILE_OBJECT *)CreateKernelObject(sizeof(FILE_OBJECT));
133 if(hstdout == NULL)
134 return 1;
135 hstdout->common.magic = KERNEL_OBJECT_FILE;
136 hstdout->fd = 1;
137 hstdout->type = FILE_TYPE_CHAR;
138 hstdout->misc_flags = 0;
140 /* Create the standard error handle
142 hstderr = (FILE_OBJECT *)CreateKernelObject(sizeof(FILE_OBJECT));
143 if(hstderr == NULL)
144 return 1;
145 hstderr->common.magic = KERNEL_OBJECT_FILE;
146 hstderr->fd = 2;
147 hstderr->type = FILE_TYPE_CHAR;
148 hstderr->misc_flags = 0;
150 return 0;