windows.gaming.input: Fake empty IGamepadStatics::Gamepads vector.
[wine/zf.git] / dlls / winecrt0 / delay_load.c
blob1778856aa56971f6791e91e46d4bddbc7028583b
1 /*
2 * Support for delayed imports
4 * Copyright 2005 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
22 #include "windef.h"
23 #include "winbase.h"
24 #include "delayloadhandler.h"
26 WINBASEAPI void *WINAPI DelayLoadFailureHook( LPCSTR name, LPCSTR function );
28 #ifdef _WIN32
30 extern IMAGE_DOS_HEADER __ImageBase;
32 WINBASEAPI void *WINAPI ResolveDelayLoadedAPI( void* base, const IMAGE_DELAYLOAD_DESCRIPTOR* desc,
33 PDELAYLOAD_FAILURE_DLL_CALLBACK dllhook,
34 PDELAYLOAD_FAILURE_SYSTEM_ROUTINE syshook,
35 IMAGE_THUNK_DATA* addr, ULONG flags );
37 FARPROC WINAPI __delayLoadHelper2( const IMAGE_DELAYLOAD_DESCRIPTOR *descr, IMAGE_THUNK_DATA *addr )
39 return ResolveDelayLoadedAPI( &__ImageBase, descr, NULL, DelayLoadFailureHook, addr, 0 );
42 #else /* _WIN32 */
44 struct ImgDelayDescr
46 DWORD_PTR grAttrs;
47 LPCSTR szName;
48 HMODULE *phmod;
49 IMAGE_THUNK_DATA *pIAT;
50 const IMAGE_THUNK_DATA *pINT;
51 const IMAGE_THUNK_DATA *pBoundIAT;
52 const IMAGE_THUNK_DATA *pUnloadIAT;
53 DWORD_PTR dwTimeStamp;
56 extern struct ImgDelayDescr __wine_spec_delay_imports[];
58 FARPROC WINAPI DECLSPEC_HIDDEN __wine_spec_delay_load( unsigned int id )
60 struct ImgDelayDescr *descr = __wine_spec_delay_imports + HIWORD(id);
61 WORD func = LOWORD(id);
62 FARPROC proc;
64 if (!*descr->phmod) *descr->phmod = LoadLibraryA( descr->szName );
65 if (!*descr->phmod ||
66 !(proc = GetProcAddress( *descr->phmod, (LPCSTR)descr->pINT[func].u1.Function )))
67 proc = DelayLoadFailureHook( descr->szName, (LPCSTR)descr->pINT[func].u1.Function );
68 descr->pIAT[func].u1.Function = (ULONG_PTR)proc;
69 return proc;
72 #if defined(__GNUC__) && !defined(__APPLE__) /* we can't support destructors properly on Mac OS */
73 static void free_delay_imports(void) __attribute__((destructor));
74 static void free_delay_imports(void)
76 struct ImgDelayDescr *descr;
77 for (descr = __wine_spec_delay_imports; descr->szName; descr++)
78 if (*descr->phmod) FreeLibrary( *descr->phmod );
80 #endif
82 #endif /* _WIN32 */