Send LVN_DELETEITEM notification first, to avoid crashes if the app
[wine.git] / scheduler / handle.c
blob4b1a71cccb2b48f5540c6e574a6505f7642299f1
1 /*
2 * Win32 process handles
4 * Copyright 1998 Alexandre Julliard
5 */
7 #include <assert.h>
8 #include <stdio.h>
9 #include <unistd.h>
10 #include "winbase.h"
11 #include "server.h"
12 #include "winerror.h"
13 #include "debugtools.h"
15 DEFAULT_DEBUG_CHANNEL(win32);
17 /*********************************************************************
18 * CloseHandle (KERNEL.11)
19 * CloseHandle (WIN32S16.11)
20 * CloseHandle (KERNEL32.@)
22 BOOL WINAPI CloseHandle( HANDLE handle )
24 NTSTATUS status;
26 /* stdio handles need special treatment */
27 if ((handle == STD_INPUT_HANDLE) ||
28 (handle == STD_OUTPUT_HANDLE) ||
29 (handle == STD_ERROR_HANDLE))
30 handle = GetStdHandle( handle );
32 status = NtClose( handle );
33 if (status) SetLastError( RtlNtStatusToDosError(status) );
34 return !status;
38 /*********************************************************************
39 * GetHandleInformation (KERNEL32.336)
41 BOOL WINAPI GetHandleInformation( HANDLE handle, LPDWORD flags )
43 BOOL ret;
44 SERVER_START_REQ
46 struct set_handle_info_request *req = server_alloc_req( sizeof(*req), 0 );
47 req->handle = handle;
48 req->flags = 0;
49 req->mask = 0;
50 req->fd = -1;
51 ret = !server_call( REQ_SET_HANDLE_INFO );
52 if (ret && flags) *flags = req->old_flags;
54 SERVER_END_REQ;
55 return ret;
59 /*********************************************************************
60 * SetHandleInformation (KERNEL32.653)
62 BOOL WINAPI SetHandleInformation( HANDLE handle, DWORD mask, DWORD flags )
64 BOOL ret;
65 SERVER_START_REQ
67 struct set_handle_info_request *req = server_alloc_req( sizeof(*req), 0 );
68 req->handle = handle;
69 req->flags = flags;
70 req->mask = mask;
71 req->fd = -1;
72 ret = !server_call( REQ_SET_HANDLE_INFO );
74 SERVER_END_REQ;
75 return ret;
79 /*********************************************************************
80 * DuplicateHandle (KERNEL32.192)
82 BOOL WINAPI DuplicateHandle( HANDLE source_process, HANDLE source,
83 HANDLE dest_process, HANDLE *dest,
84 DWORD access, BOOL inherit, DWORD options )
86 BOOL ret;
87 SERVER_START_REQ
89 struct dup_handle_request *req = server_alloc_req( sizeof(*req), 0 );
91 req->src_process = source_process;
92 req->src_handle = source;
93 req->dst_process = dest_process;
94 req->access = access;
95 req->inherit = inherit;
96 req->options = options;
98 ret = !server_call( REQ_DUP_HANDLE );
99 if (ret)
101 if (dest) *dest = req->handle;
102 if (req->fd != -1) close( req->fd );
105 SERVER_END_REQ;
106 return ret;
110 /***********************************************************************
111 * ConvertToGlobalHandle (KERNEL.476)
112 * ConvertToGlobalHandle (KERNEL32.@)
114 HANDLE WINAPI ConvertToGlobalHandle(HANDLE hSrc)
116 HANDLE ret = INVALID_HANDLE_VALUE;
117 DuplicateHandle( GetCurrentProcess(), hSrc, GetCurrentProcess(), &ret, 0, FALSE,
118 DUP_HANDLE_MAKE_GLOBAL | DUP_HANDLE_SAME_ACCESS | DUP_HANDLE_CLOSE_SOURCE );
119 return ret;
122 /***********************************************************************
123 * SetHandleContext (KERNEL32.@)
125 BOOL WINAPI SetHandleContext(HANDLE hnd,DWORD context) {
126 FIXME("(%d,%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);
127 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
128 return FALSE;
131 /***********************************************************************
132 * GetHandleContext (KERNEL32.@)
134 DWORD WINAPI GetHandleContext(HANDLE hnd) {
135 FIXME("(%d), 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);
136 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
137 return 0;
140 /***********************************************************************
141 * CreateSocketHandle (KERNEL32.@)
143 HANDLE WINAPI CreateSocketHandle(void) {
144 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");
145 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
146 return INVALID_HANDLE_VALUE;