Release 951212
[wine/gsoc-2012-control.git] / if1632 / relay32.c
blob67c646173615551c7644fa575c6ac6008c355294
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 "stddebug.h"
19 /* #define DEBUG_RELAY */
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(strncasecmp(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, *ename;
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 if(!dll) {
89 if(!wine_files || !wine_files->name ||
90 strcasecmp(dll_name, wine_files->name)) {
91 LoadModule(dll_name, (LPVOID) -1);
92 if(!wine_files || !wine_files->name ||
93 strcasecmp(dll_name, wine_files->name))
94 return 0;
96 load_addr = wine_files->load_addr;
97 pe_exports = wine_files->pe->pe_export;
98 ordinal = (u_short *) (((char *) load_addr) + (int) pe_exports->Address_Of_Name_Ordinals);
99 function = (u_long *) (((char *) load_addr) + (int) pe_exports->AddressOfFunctions);
100 name = (u_char **) (((char *) load_addr) + (int) pe_exports->AddressOfNames);
101 /* import by ordinal */
102 if(!item){
103 return 0;
105 /* hint is correct */
106 #if 0
107 if(hint && hint<dll->size &&
108 dll->functions[hint].name &&
109 strcmp(item,dll->functions[hint].name)==0)
110 return dll->functions[hint].definition;
111 #endif
112 /* hint is incorrect, search for name */
113 for(i=0;i<pe_exports->Number_Of_Functions;i++)
114 if (name[i] && !strcmp(item,name[i]+load_addr))
115 return function[i]+(char *)load_addr;
117 /* function at hint has no name (unimplemented) */
118 #if 0
119 if(hint && hint<dll->size && !dll->functions[hint].name)
121 dll->functions[hint].name=strdup(item);
122 dprintf_module(stddeb, "Returning unimplemented function %s.%d\n",
123 dll_name,hint);
124 return dll->functions[hint].definition;
126 #endif
127 printf("Not found\n");
128 return 0;
130 /* import by ordinal */
131 if(!item){
132 if(hint && hint<dll->size)return dll->functions[hint].definition;
133 return 0;
135 /* hint is correct */
136 if(hint && hint<dll->size &&
137 dll->functions[hint].name &&
138 strcmp(item,dll->functions[hint].name)==0)
139 return dll->functions[hint].definition;
140 /* hint is incorrect, search for name */
141 for(i=0;i<dll->size;i++)
142 if (dll->functions[i].name && !strcmp(item,dll->functions[i].name))
143 return dll->functions[i].definition;
145 /* function at hint has no name (unimplemented) */
146 if(hint && hint<dll->size && !dll->functions[hint].name)
148 dll->functions[hint].name=strdup(item);
149 dprintf_module(stddeb, "Returning unimplemented function %s.%d\n",
150 dll_name,hint);
151 return dll->functions[hint].definition;
153 printf("Not found\n");
154 return 0;
157 void RELAY32_DebugEnter(char *dll,char *name)
159 dprintf_relay(stddeb, "Entering %s.%s\n",dll,name);
162 LONG RELAY32_CallWindowProc( WNDPROC func, int hwnd, int message,
163 int wParam, int lParam )
165 int ret;
166 __asm__ (
167 "push %1;"
168 "push %2;"
169 "push %3;"
170 "push %4;"
171 "call %5;"
172 : "=a" (ret)
173 : "g" (lParam), "g" (wParam), "g" (message), "g" (hwnd), "g" (func)
175 return ret;