Added some missing definitions.
[wine/multimedia.git] / relay32 / builtin32.c
bloba56378dacb1f6a44b73bb9e467d432d766910948
1 /*
2 * Win32 builtin functions
4 * Copyright 1997 Alexandre Julliard
5 */
7 #include "config.h"
9 #include <assert.h>
10 #include <string.h>
11 #include <stdio.h>
12 #include <ctype.h>
13 #ifdef HAVE_DL_API
14 #include <dlfcn.h>
15 #endif
16 #include <sys/types.h>
17 #ifdef HAVE_SYS_MMAN_H
18 #include <sys/mman.h>
19 #endif
21 #include "windef.h"
22 #include "wine/winbase16.h"
23 #include "wine/library.h"
24 #include "global.h"
25 #include "module.h"
26 #include "heap.h"
27 #include "main.h"
28 #include "winerror.h"
29 #include "server.h"
30 #include "debugtools.h"
32 DEFAULT_DEBUG_CHANNEL(module);
33 DECLARE_DEBUG_CHANNEL(relay);
35 extern void RELAY_SetupDLL( const char *module );
37 static HMODULE main_module;
39 /***********************************************************************
40 * BUILTIN32_dlopen
42 void *BUILTIN32_dlopen( const char *name )
44 #ifdef HAVE_DL_API
45 void *handle;
47 if (!(handle = wine_dll_load( name )))
49 LPSTR pErr;
50 pErr = dlerror();
51 if (strstr(pErr, "undefined symbol")) /* undef symbol -> ERR() */
52 ERR("failed to load %s: %s\n", name, pErr);
53 else /* WARN() for libraries that are supposed to be native */
54 WARN("failed to load %s: %s\n", name, pErr );
56 return handle;
57 #else
58 return NULL;
59 #endif
62 /***********************************************************************
63 * BUILTIN32_dlclose
65 int BUILTIN32_dlclose( void *handle )
67 #ifdef HAVE_DL_API
68 /* FIXME: should unregister descriptors first */
69 /* return dlclose( handle ); */
70 #endif
71 return 0;
75 /***********************************************************************
76 * load_library
78 * Load a library in memory; callback function for wine_dll_register
80 static void load_library( void *base, const char *filename )
82 HMODULE module = (HMODULE)base;
83 WINE_MODREF *wm;
85 if (!base)
87 ERR("could not map image for %s\n", filename ? filename : "main exe" );
88 return;
91 if (!(PE_HEADER(module)->FileHeader.Characteristics & IMAGE_FILE_DLL))
93 /* if we already have an executable, ignore this one */
94 if (!main_module) main_module = module;
95 return; /* don't create the modref here, will be done later on */
98 if (GetModuleHandleA( filename ))
99 MESSAGE( "Warning: loading builtin %s, but native version already present. Expect trouble.\n", filename );
101 /* Create 32-bit MODREF */
102 if (!(wm = PE_CreateModule( module, filename, 0, -1, TRUE )))
104 ERR( "can't load %s\n", filename );
105 SetLastError( ERROR_OUTOFMEMORY );
106 return;
108 TRACE( "loaded %s %p %x\n", filename, wm, module );
109 wm->refCount++; /* we don't support freeing builtin dlls (FIXME)*/
111 /* setup relay debugging entry points */
112 if (TRACE_ON(relay)) RELAY_SetupDLL( (void *)module );
116 /***********************************************************************
117 * BUILTIN32_LoadLibraryExA
119 * Partly copied from the original PE_ version.
122 WINE_MODREF *BUILTIN32_LoadLibraryExA(LPCSTR path, DWORD flags)
124 WINE_MODREF *wm;
125 char dllname[20], *p;
126 LPCSTR name;
127 void *handle;
129 /* Fix the name in case we have a full path and extension */
130 name = path;
131 if ((p = strrchr( name, '\\' ))) name = p + 1;
132 if ((p = strrchr( name, '/' ))) name = p + 1;
134 if (strlen(name) >= sizeof(dllname)-4) goto error;
136 strcpy( dllname, name );
137 p = strrchr( dllname, '.' );
138 if (!p) strcat( dllname, ".dll" );
140 if (!(handle = BUILTIN32_dlopen( dllname ))) goto error;
142 if (!(wm = MODULE_FindModule( path ))) wm = MODULE_FindModule( dllname );
143 if (!wm)
145 ERR( "loaded .so but dll %s still not found\n", dllname );
146 /* wine_dll_unload( handle );*/
147 return NULL;
149 wm->dlhandle = handle;
150 return wm;
152 error:
153 SetLastError( ERROR_FILE_NOT_FOUND );
154 return NULL;
157 /***********************************************************************
158 * BUILTIN32_Init
160 * Initialize loading callbacks and return HMODULE of main exe.
161 * 'main' is the main exe in case if was already loaded from a PE file.
163 HMODULE BUILTIN32_LoadExeModule( HMODULE main )
165 main_module = main;
166 wine_dll_set_callback( load_library );
167 if (!main_module)
168 MESSAGE( "No built-in EXE module loaded! Did you create a .spec file?\n" );
169 return main_module;
173 /***********************************************************************
174 * BUILTIN32_RegisterDLL
176 * Register a built-in DLL descriptor.
178 void BUILTIN32_RegisterDLL( const IMAGE_NT_HEADERS *header, const char *filename )
180 extern void __wine_dll_register( const IMAGE_NT_HEADERS *header, const char *filename );
181 __wine_dll_register( header, filename );