In CBPaintText use the text size as returned by LB_GETTEXT. The size
[wine.git] / relay32 / builtin32.c
blob531f74f015773d5461d206fb78ce88cec6d08f97
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 #include <sys/types.h>
14 #ifdef HAVE_SYS_MMAN_H
15 #include <sys/mman.h>
16 #endif
18 #include "windef.h"
19 #include "wine/winbase16.h"
20 #include "wine/library.h"
21 #include "module.h"
22 #include "file.h"
23 #include "winerror.h"
24 #include "wine/server.h"
25 #include "debugtools.h"
27 DEFAULT_DEBUG_CHANNEL(module);
28 DECLARE_DEBUG_CHANNEL(relay);
30 extern void RELAY_SetupDLL( const char *module );
32 static HMODULE main_module;
34 /***********************************************************************
35 * BUILTIN32_dlopen
37 void *BUILTIN32_dlopen( const char *name )
39 void *handle;
40 char error[256];
42 if (!(handle = wine_dll_load( name, error, sizeof(error) )))
44 if (strstr(error, "cannot open") || strstr(error, "open failed") ||
45 (strstr(error, "Shared object") && strstr(error, "not found"))) {
46 /* The file does not exist -> WARN() */
47 WARN("cannot open .so lib for builtin %s: %s\n", name, error);
48 } else {
49 /* ERR() for all other errors (missing functions, ...) */
50 ERR("failed to load .so lib for builtin %s: %s\n", name, error );
53 return handle;
56 /***********************************************************************
57 * BUILTIN32_dlclose
59 int BUILTIN32_dlclose( void *handle )
61 /* FIXME: should unregister descriptors first */
62 /* wine_dll_unload( handle ); */
63 return 0;
67 /***********************************************************************
68 * load_library
70 * Load a library in memory; callback function for wine_dll_register
72 static void load_library( void *base, const char *filename )
74 HMODULE module = (HMODULE)base;
75 WINE_MODREF *wm;
77 if (!base)
79 ERR("could not map image for %s\n", filename ? filename : "main exe" );
80 return;
83 if (!(PE_HEADER(module)->FileHeader.Characteristics & IMAGE_FILE_DLL))
85 /* if we already have an executable, ignore this one */
86 if (!main_module) main_module = module;
87 return; /* don't create the modref here, will be done later on */
90 if (GetModuleHandleA( filename ))
91 MESSAGE( "Warning: loading builtin %s, but native version already present. Expect trouble.\n", filename );
93 /* Create 32-bit MODREF */
94 if (!(wm = PE_CreateModule( module, filename, 0, 0, TRUE )))
96 ERR( "can't load %s\n", filename );
97 SetLastError( ERROR_OUTOFMEMORY );
98 return;
100 TRACE( "loaded %s %p %x\n", filename, wm, module );
101 wm->refCount++; /* we don't support freeing builtin dlls (FIXME)*/
103 /* setup relay debugging entry points */
104 if (TRACE_ON(relay)) RELAY_SetupDLL( (void *)module );
108 /***********************************************************************
109 * BUILTIN32_LoadLibraryExA
111 * Partly copied from the original PE_ version.
114 WINE_MODREF *BUILTIN32_LoadLibraryExA(LPCSTR path, DWORD flags)
116 WINE_MODREF *wm;
117 char dllname[20], *p;
118 LPCSTR name;
119 void *handle;
121 /* Fix the name in case we have a full path and extension */
122 name = path;
123 if ((p = strrchr( name, '\\' ))) name = p + 1;
124 if ((p = strrchr( name, '/' ))) name = p + 1;
126 if (strlen(name) >= sizeof(dllname)-4) goto error;
128 strcpy( dllname, name );
129 p = strrchr( dllname, '.' );
130 if (!p) strcat( dllname, ".dll" );
131 for (p = dllname; *p; p++) *p = FILE_tolower(*p);
133 if (!(handle = BUILTIN32_dlopen( dllname ))) goto error;
135 if (!(wm = MODULE_FindModule( path ))) wm = MODULE_FindModule( dllname );
136 if (!wm)
138 ERR( "loaded .so but dll %s still not found\n", dllname );
139 /* wine_dll_unload( handle );*/
140 return NULL;
142 wm->dlhandle = handle;
143 return wm;
145 error:
146 SetLastError( ERROR_FILE_NOT_FOUND );
147 return NULL;
150 /***********************************************************************
151 * BUILTIN32_Init
153 * Initialize loading callbacks and return HMODULE of main exe.
154 * 'main' is the main exe in case if was already loaded from a PE file.
156 HMODULE BUILTIN32_LoadExeModule( HMODULE main )
158 main_module = main;
159 wine_dll_set_callback( load_library );
160 if (!main_module)
161 MESSAGE( "No built-in EXE module loaded! Did you create a .spec file?\n" );
162 return main_module;
166 /***********************************************************************
167 * BUILTIN32_RegisterDLL
169 * Register a built-in DLL descriptor.
171 void BUILTIN32_RegisterDLL( const IMAGE_NT_HEADERS *header, const char *filename )
173 extern void __wine_dll_register( const IMAGE_NT_HEADERS *header, const char *filename );
174 __wine_dll_register( header, filename );