WM_PAINT(wParam) might be a valid HDC.
[wine/multimedia.git] / scheduler / handle.c
blobb3f2ed0f85b102b406b243a8b5b9679b934d8099
1 /*
2 * Win32 process handles
4 * Copyright 1998 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
23 #include <assert.h>
24 #include <stdio.h>
25 #ifdef HAVE_IO_H
26 # include <io.h>
27 #endif
28 #ifdef HAVE_UNISTD_H
29 # include <unistd.h>
30 #endif
31 #include "winbase.h"
32 #include "wine/server.h"
33 #include "winerror.h"
34 #include "wine/debug.h"
35 #include "../kernel/kernel_private.h" /* FIXME: to be changed when moving file to dlls/kernel */
37 WINE_DEFAULT_DEBUG_CHANNEL(win32);
39 /*********************************************************************
40 * CloseW32Handle (KERNEL.474)
41 * CloseHandle (KERNEL32.@)
43 BOOL WINAPI CloseHandle( HANDLE handle )
45 NTSTATUS status;
47 /* stdio handles need special treatment */
48 if ((handle == (HANDLE)STD_INPUT_HANDLE) ||
49 (handle == (HANDLE)STD_OUTPUT_HANDLE) ||
50 (handle == (HANDLE)STD_ERROR_HANDLE))
51 handle = GetStdHandle( (DWORD)handle );
53 if (is_console_handle(handle))
54 return CloseConsoleHandle(handle);
56 status = NtClose( handle );
57 if (status) SetLastError( RtlNtStatusToDosError(status) );
58 return !status;
62 /*********************************************************************
63 * GetHandleInformation (KERNEL32.@)
65 BOOL WINAPI GetHandleInformation( HANDLE handle, LPDWORD flags )
67 BOOL ret;
68 SERVER_START_REQ( set_handle_info )
70 req->handle = handle;
71 req->flags = 0;
72 req->mask = 0;
73 req->fd = -1;
74 ret = !wine_server_call_err( req );
75 if (ret && flags) *flags = reply->old_flags;
77 SERVER_END_REQ;
78 return ret;
82 /*********************************************************************
83 * SetHandleInformation (KERNEL32.@)
85 BOOL WINAPI SetHandleInformation( HANDLE handle, DWORD mask, DWORD flags )
87 BOOL ret;
88 SERVER_START_REQ( set_handle_info )
90 req->handle = handle;
91 req->flags = flags;
92 req->mask = mask;
93 req->fd = -1;
94 ret = !wine_server_call_err( req );
96 SERVER_END_REQ;
97 return ret;
101 /*********************************************************************
102 * DuplicateHandle (KERNEL32.@)
104 BOOL WINAPI DuplicateHandle( HANDLE source_process, HANDLE source,
105 HANDLE dest_process, HANDLE *dest,
106 DWORD access, BOOL inherit, DWORD options )
108 NTSTATUS status;
110 if (is_console_handle(source))
112 /* FIXME: this test is not sufficient, we need to test process ids, not handles */
113 if (source_process != dest_process ||
114 source_process != GetCurrentProcess())
116 SetLastError(ERROR_INVALID_PARAMETER);
117 return FALSE;
119 *dest = DuplicateConsoleHandle( source, access, inherit, options );
120 return (*dest != INVALID_HANDLE_VALUE);
122 status = NtDuplicateObject( source_process, source, dest_process, dest,
123 access, inherit ? OBJ_INHERIT : 0, options );
124 if (status) SetLastError( RtlNtStatusToDosError(status) );
125 return !status;
129 /***********************************************************************
130 * ConvertToGlobalHandle (KERNEL.476)
131 * ConvertToGlobalHandle (KERNEL32.@)
133 HANDLE WINAPI ConvertToGlobalHandle(HANDLE hSrc)
135 HANDLE ret = INVALID_HANDLE_VALUE;
136 DuplicateHandle( GetCurrentProcess(), hSrc, GetCurrentProcess(), &ret, 0, FALSE,
137 DUP_HANDLE_MAKE_GLOBAL | DUP_HANDLE_SAME_ACCESS | DUP_HANDLE_CLOSE_SOURCE );
138 return ret;
141 /***********************************************************************
142 * SetHandleContext (KERNEL32.@)
144 BOOL WINAPI SetHandleContext(HANDLE hnd,DWORD context) {
145 FIXME("(%p,%ld), stub. In case this got called by WSOCK32/WS2_32: the external WINSOCK DLLs won't work with WINE, don't use them.\n",hnd,context);
146 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
147 return FALSE;
150 /***********************************************************************
151 * GetHandleContext (KERNEL32.@)
153 DWORD WINAPI GetHandleContext(HANDLE hnd) {
154 FIXME("(%p), stub. In case this got called by WSOCK32/WS2_32: the external WINSOCK DLLs won't work with WINE, don't use them.\n",hnd);
155 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
156 return 0;
159 /***********************************************************************
160 * CreateSocketHandle (KERNEL32.@)
162 HANDLE WINAPI CreateSocketHandle(void) {
163 FIXME("(), stub. In case this got called by WSOCK32/WS2_32: the external WINSOCK DLLs won't work with WINE, don't use them.\n");
164 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
165 return INVALID_HANDLE_VALUE;