Document BSTR functions, add SetOANoCache().
[wine] / scheduler / handle.c
1 /*
2  * Win32 process handles
3  *
4  * Copyright 1998 Alexandre Julliard
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "config.h"
22
23 #include <assert.h>
24 #include <stdarg.h>
25 #include <stdio.h>
26 #ifdef HAVE_IO_H
27 # include <io.h>
28 #endif
29 #ifdef HAVE_UNISTD_H
30 # include <unistd.h>
31 #endif
32 #include "windef.h"
33 #include "winbase.h"
34 #include "wine/server.h"
35 #include "winerror.h"
36 #include "wine/debug.h"
37 #include "../kernel/kernel_private.h"  /* FIXME: to be changed when moving file to dlls/kernel */
38
39 WINE_DEFAULT_DEBUG_CHANNEL(win32);
40
41 /*********************************************************************
42  *           CloseW32Handle (KERNEL.474)
43  *           CloseHandle    (KERNEL32.@)
44  */
45 BOOL WINAPI CloseHandle( HANDLE handle )
46 {
47     NTSTATUS status;
48
49     /* stdio handles need special treatment */
50     if ((handle == (HANDLE)STD_INPUT_HANDLE) ||
51         (handle == (HANDLE)STD_OUTPUT_HANDLE) ||
52         (handle == (HANDLE)STD_ERROR_HANDLE))
53         handle = GetStdHandle( (DWORD)handle );
54
55     if (is_console_handle(handle))
56         return CloseConsoleHandle(handle);
57
58     status = NtClose( handle );
59     if (status) SetLastError( RtlNtStatusToDosError(status) );
60     return !status;
61 }
62
63
64 /*********************************************************************
65  *           GetHandleInformation   (KERNEL32.@)
66  */
67 BOOL WINAPI GetHandleInformation( HANDLE handle, LPDWORD flags )
68 {
69     BOOL ret;
70     SERVER_START_REQ( set_handle_info )
71     {
72         req->handle = handle;
73         req->flags  = 0;
74         req->mask   = 0;
75         req->fd     = -1;
76         ret = !wine_server_call_err( req );
77         if (ret && flags) *flags = reply->old_flags;
78     }
79     SERVER_END_REQ;
80     return ret;
81 }
82
83
84 /*********************************************************************
85  *           SetHandleInformation   (KERNEL32.@)
86  */
87 BOOL WINAPI SetHandleInformation( HANDLE handle, DWORD mask, DWORD flags )
88 {
89     BOOL ret;
90     SERVER_START_REQ( set_handle_info )
91     {
92         req->handle = handle;
93         req->flags  = flags;
94         req->mask   = mask;
95         req->fd     = -1;
96         ret = !wine_server_call_err( req );
97     }
98     SERVER_END_REQ;
99     return ret;
100 }
101
102
103 /*********************************************************************
104  *           DuplicateHandle   (KERNEL32.@)
105  */
106 BOOL WINAPI DuplicateHandle( HANDLE source_process, HANDLE source,
107                              HANDLE dest_process, HANDLE *dest,
108                              DWORD access, BOOL inherit, DWORD options )
109 {
110     NTSTATUS status;
111
112     if (is_console_handle(source))
113     {
114         /* FIXME: this test is not sufficient, we need to test process ids, not handles */
115         if (source_process != dest_process ||
116             source_process != GetCurrentProcess())
117         {
118             SetLastError(ERROR_INVALID_PARAMETER);
119             return FALSE;
120         }
121         *dest = DuplicateConsoleHandle( source, access, inherit, options );
122         return (*dest != INVALID_HANDLE_VALUE);
123     }
124     status = NtDuplicateObject( source_process, source, dest_process, dest,
125                                 access, inherit ? OBJ_INHERIT : 0, options );
126     if (status) SetLastError( RtlNtStatusToDosError(status) );
127     return !status;
128 }
129
130
131 /***********************************************************************
132  *           ConvertToGlobalHandle              (KERNEL.476)
133  *           ConvertToGlobalHandle              (KERNEL32.@)
134  */
135 HANDLE WINAPI ConvertToGlobalHandle(HANDLE hSrc)
136 {
137     HANDLE ret = INVALID_HANDLE_VALUE;
138     DuplicateHandle( GetCurrentProcess(), hSrc, GetCurrentProcess(), &ret, 0, FALSE,
139                      DUP_HANDLE_MAKE_GLOBAL | DUP_HANDLE_SAME_ACCESS | DUP_HANDLE_CLOSE_SOURCE );
140     return ret;
141 }
142
143 /***********************************************************************
144  *           SetHandleContext                   (KERNEL32.@)
145  */
146 BOOL WINAPI SetHandleContext(HANDLE hnd,DWORD context) {
147     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);
148     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
149     return FALSE;
150 }
151
152 /***********************************************************************
153  *           GetHandleContext                   (KERNEL32.@)
154  */
155 DWORD WINAPI GetHandleContext(HANDLE hnd) {
156     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);
157     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
158     return 0;
159 }
160
161 /***********************************************************************
162  *           CreateSocketHandle                 (KERNEL32.@)
163  */
164 HANDLE WINAPI CreateSocketHandle(void) {
165     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");
166     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
167     return INVALID_HANDLE_VALUE;
168 }