- Implemented semi-stubs for GetOpenFileNamePreviewA/W and
[wine/multimedia.git] / loader / task.c
blob031167b680c4099875d0fc11865a8fd1775ff990
1 /*
2 * Task functions
4 * Copyright 1995 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"
22 #include "wine/port.h"
24 #include <stdlib.h>
25 #include <string.h>
26 #include <assert.h>
27 #ifdef HAVE_UNISTD_H
28 # include <unistd.h>
29 #endif
31 #include "winbase.h"
32 #include "wingdi.h"
33 #include "winnt.h"
34 #include "winuser.h"
36 #include "wine/winbase16.h"
37 #include "drive.h"
38 #include "file.h"
39 #include "global.h"
40 #include "instance.h"
41 #include "module.h"
42 #include "winternl.h"
43 #include "selectors.h"
44 #include "wine/server.h"
45 #include "stackframe.h"
46 #include "task.h"
47 #include "thread.h"
48 #include "toolhelp.h"
50 #include "wine/debug.h"
52 WINE_DEFAULT_DEBUG_CHANNEL(task);
54 static THHOOK DefaultThhook;
55 THHOOK *pThhook = &DefaultThhook;
57 #define hFirstTask (pThhook->HeadTDB)
59 /***********************************************************************
60 * TASK_GetPtr
62 static TDB *TASK_GetPtr( HTASK16 hTask )
64 return GlobalLock16( hTask );
68 /***********************************************************************
69 * TASK_GetCurrent
71 TDB *TASK_GetCurrent(void)
73 return TASK_GetPtr( GetCurrentTask() );
77 /***********************************************************************
78 * GetCurrentTask (KERNEL32.@)
80 HTASK16 WINAPI GetCurrentTask(void)
82 return NtCurrentTeb()->htask16;
85 /***********************************************************************
86 * GetCurrentPDB (KERNEL.37)
88 * UNDOC: returns PSP of KERNEL in high word
90 DWORD WINAPI GetCurrentPDB16(void)
92 TDB *pTask;
94 if (!(pTask = TASK_GetCurrent())) return 0;
95 return MAKELONG(pTask->hPDB, 0); /* FIXME */
99 /***********************************************************************
100 * GetExePtrHelper
102 static inline HMODULE16 GetExePtrHelper( HANDLE16 handle, HTASK16 *hTask )
104 char *ptr;
105 HANDLE16 owner;
107 /* Check for module handle */
109 if (!(ptr = GlobalLock16( handle ))) return 0;
110 if (((NE_MODULE *)ptr)->magic == IMAGE_OS2_SIGNATURE) return handle;
112 /* Search for this handle inside all tasks */
114 *hTask = hFirstTask;
115 while (*hTask)
117 TDB *pTask = TASK_GetPtr( *hTask );
118 if ((*hTask == handle) ||
119 (pTask->hInstance == handle) ||
120 (pTask->hQueue == handle) ||
121 (pTask->hPDB == handle)) return pTask->hModule;
122 *hTask = pTask->hNext;
125 /* Check the owner for module handle */
127 owner = FarGetOwner16( handle );
128 if (!(ptr = GlobalLock16( owner ))) return 0;
129 if (((NE_MODULE *)ptr)->magic == IMAGE_OS2_SIGNATURE) return owner;
131 /* Search for the owner inside all tasks */
133 *hTask = hFirstTask;
134 while (*hTask)
136 TDB *pTask = TASK_GetPtr( *hTask );
137 if ((*hTask == owner) ||
138 (pTask->hInstance == owner) ||
139 (pTask->hQueue == owner) ||
140 (pTask->hPDB == owner)) return pTask->hModule;
141 *hTask = pTask->hNext;
144 return 0;
147 /***********************************************************************
148 * GetExePtr (KERNEL.133)
150 HMODULE16 WINAPI WIN16_GetExePtr( HANDLE16 handle )
152 HTASK16 hTask = 0;
153 HMODULE16 hModule = GetExePtrHelper( handle, &hTask );
154 STACK16FRAME *frame = CURRENT_STACK16;
155 frame->ecx = hModule;
156 if (hTask) frame->es = hTask;
157 return hModule;
161 /***********************************************************************
162 * K228 (KERNEL.228)
164 HMODULE16 WINAPI GetExePtr( HANDLE16 handle )
166 HTASK16 hTask = 0;
167 return GetExePtrHelper( handle, &hTask );