Release 960131
[wine/multimedia.git] / if1632 / relay32.c
bloba380483df2bce910437e08e3659a583e5c1b2d44
1 /*
2 * Copyright 1995 Martin von Loewis
3 */
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <sys/types.h>
9 #include <sys/stat.h>
10 #include <fcntl.h>
11 #include <unistd.h>
12 #include <errno.h>
13 #include "windows.h"
14 #include "dlls.h"
15 #include "pe_image.h"
16 #include "peexe.h"
17 #include "relay32.h"
18 #include "xmalloc.h"
19 #include "stddebug.h"
20 #include "debug.h"
22 WIN32_builtin *WIN32_builtin_list;
24 /* Functions are in generated code */
25 void ADVAPI32_Init();
26 void COMDLG32_Init();
27 void GDI32_Init();
28 void KERNEL32_Init();
29 void SHELL32_Init();
30 void USER32_Init();
31 void WINPROCS32_Init();
33 int RELAY32_Init(void)
35 #ifndef WINELIB
36 /* Add a call for each DLL */
37 ADVAPI32_Init();
38 COMDLG32_Init();
39 GDI32_Init();
40 KERNEL32_Init();
41 SHELL32_Init();
42 USER32_Init();
43 WINPROCS32_Init();
44 #endif
45 /* Why should it fail, anyways? */
46 return 1;
49 WIN32_builtin *RELAY32_GetBuiltinDLL(char *name)
51 WIN32_builtin *it;
52 size_t len;
53 char *cp;
55 len = (cp=strchr(name,'.')) ? (cp-name) : strlen(name);
56 for(it=WIN32_builtin_list;it;it=it->next)
57 if(lstrncmpi(name,it->name,len)==0)
58 return it;
59 return NULL;
62 void RELAY32_Unimplemented(char *dll, int item)
64 WIN32_builtin *Dll;
65 fprintf( stderr, "No handler for routine %s.%d", dll, item);
66 Dll=RELAY32_GetBuiltinDLL(dll);
67 if(Dll && Dll->functions[item].name)
68 fprintf(stderr, "(%s?)\n", Dll->functions[item].name);
69 else
70 fprintf(stderr, "\n");
71 fflush(stderr);
72 exit(1);
75 void *RELAY32_GetEntryPoint(char *dll_name, char *item, int hint)
77 WIN32_builtin *dll;
78 int i;
79 u_short * ordinal;
80 u_long * function;
81 u_char ** name;
82 struct PE_Export_Directory * pe_exports;
83 unsigned int load_addr;
85 dprintf_module(stddeb, "Looking for %s in %s, hint %x\n",
86 item ? item: "(no name)", dll_name, hint);
87 dll=RELAY32_GetBuiltinDLL(dll_name);
88 /* FIXME: This should deal with built-in DLLs only. See pe_module on
89 loading PE DLLs */
90 if(!dll)
91 return 0;
92 #if 0
93 if(!dll) {
94 if(!wine_files || !wine_files->name ||
95 lstrcmpi(dll_name, wine_files->name)) {
96 LoadModule(dll_name, (LPVOID) -1);
97 if(!wine_files || !wine_files->name ||
98 lstrcmpi(dll_name, wine_files->name))
99 return 0;
101 load_addr = wine_files->load_addr;
102 pe_exports = wine_files->pe->pe_export;
103 ordinal = (u_short *) (((char *) load_addr) + (int) pe_exports->Address_Of_Name_Ordinals);
104 function = (u_long *) (((char *) load_addr) + (int) pe_exports->AddressOfFunctions);
105 name = (u_char **) (((char *) load_addr) + (int) pe_exports->AddressOfNames);
106 /* import by ordinal */
107 if(!item){
108 return 0;
110 /* hint is correct */
111 #if 0
112 if(hint && hint<dll->size &&
113 dll->functions[hint].name &&
114 strcmp(item,dll->functions[hint].name)==0)
115 return dll->functions[hint].definition;
116 #endif
117 /* hint is incorrect, search for name */
118 for(i=0;i<pe_exports->Number_Of_Functions;i++)
119 if (name[i] && !strcmp(item,name[i]+load_addr))
120 return function[i]+(char *)load_addr;
122 /* function at hint has no name (unimplemented) */
123 #if 0
124 if(hint && hint<dll->size && !dll->functions[hint].name)
126 dll->functions[hint].name=xstrdup(item);
127 dprintf_module(stddeb, "Returning unimplemented function %s.%d\n",
128 dll_name,hint);
129 return dll->functions[hint].definition;
131 #endif
132 printf("Not found\n");
133 return 0;
135 #endif
136 /* import by ordinal */
137 if(!item){
138 if(hint && hint<dll->size)return dll->functions[hint].definition;
139 return 0;
141 /* hint is correct */
142 if(hint && hint<dll->size &&
143 dll->functions[hint].name &&
144 strcmp(item,dll->functions[hint].name)==0)
145 return dll->functions[hint].definition;
146 /* hint is incorrect, search for name */
147 for(i=0;i<dll->size;i++)
148 if (dll->functions[i].name && !strcmp(item,dll->functions[i].name))
149 return dll->functions[i].definition;
151 /* function at hint has no name (unimplemented) */
152 if(hint && hint<dll->size && !dll->functions[hint].name)
154 dll->functions[hint].name=xstrdup(item);
155 dprintf_module(stddeb, "Returning unimplemented function %s.%d\n",
156 dll_name,hint);
157 return dll->functions[hint].definition;
159 return 0;
162 void RELAY32_DebugEnter(char *dll,char *name)
164 dprintf_relay(stddeb, "Entering %s.%s\n",dll,name);
167 LONG RELAY32_CallWindowProc( WNDPROC func, int hwnd, int message,
168 int wParam, int lParam )
170 int ret;
171 __asm__ (
172 "push %1;"
173 "push %2;"
174 "push %3;"
175 "push %4;"
176 "call %5;"
177 : "=a" (ret)
178 : "g" (lParam), "g" (wParam), "g" (message), "g" (hwnd), "g" (func)
180 return ret;