2 * Modules & Libraries functions
4 static char Copyright[] = "Copyright Martin Ayotte, 1994";
14 #include <sys/types.h>
18 #include "prototypes.h"
33 typedef MODULEENTRY *LPMODULEENTRY;
35 static LPMODULEENTRY lpModList = NULL;
37 extern struct w_files * wine_files;
39 extern struct dll_name_table_entry_s dll_builtin_table[N_BUILTINS];
42 /**********************************************************************
43 * GetModuleHandle [KERNEL.47]
45 HANDLE GetModuleHandle(LPSTR lpModuleName)
47 register struct w_files *w = wine_files;
49 printf("GetModuleHandle('%s');\n", lpModuleName);
50 printf("GetModuleHandle // searching in loaded modules\n");
52 /* printf("GetModuleHandle // '%s' \n", w->name); */
53 if (strcmp(w->name, lpModuleName) == 0) {
54 printf("GetModuleHandle('%s') return %04X \n",
55 lpModuleName, w->hinstance);
60 printf("GetModuleHandle // searching in builtin libraries\n");
61 for (i = 0; i < N_BUILTINS; i++) {
62 if (dll_builtin_table[i].dll_name == NULL) break;
63 if (strcmp(dll_builtin_table[i].dll_name, lpModuleName) == 0) {
64 printf("GetModuleHandle('%s') return %04X \n",
65 lpModuleName, 0xFF00 + i);
69 printf("GetModuleHandle('%s') not found !\n", lpModuleName);
74 /**********************************************************************
75 * GetModuleUsage [KERNEL.48]
77 int GetModuleUsage(HANDLE hModule)
80 printf("GetModuleUsage(%04X);\n", hModule);
81 w = GetFileInfo(hModule);
82 /* return w->Usage; */
87 /**********************************************************************
88 * GetModuleFilename [KERNEL.49]
90 int GetModuleFileName(HANDLE hModule, LPSTR lpFileName, short nSize)
94 printf("GetModuleFileName(%04X, %08X, %d);\n", hModule, lpFileName, nSize);
95 if (lpFileName == NULL) return 0;
96 if (nSize < 1) return 0;
97 w = GetFileInfo(hModule);
98 if (w == NULL) return 0;
100 if (str[0] == '/') str++;
101 if (nSize > strlen(str)) nSize = strlen(str) + 1;
102 strncpy(lpFileName, str, nSize);
104 printf("GetModuleFileName copied '%s' return %d \n", lpFileName, nSize);
109 /**********************************************************************
110 * LoadLibrary [KERNEL.95]
112 HANDLE LoadLibrary(LPSTR libname)
115 LPMODULEENTRY lpMod = lpModList;
116 LPMODULEENTRY lpNewMod;
118 if (FindDLLTable(libname))
120 printf("Library was a builtin - returning 0x23\n");
121 return WINE_CODE_SELECTOR;
124 printf("LoadLibrary '%s'\n", libname);
129 if (strcmp(libname, lpMod->FileName) == 0)
132 printf("LoadLibrary // already loaded hInst=%04X\n",
136 if (lpMod->lpNextModule == NULL) break;
137 lpMod = lpMod->lpNextModule;
141 hModule = GlobalAlloc(GMEM_MOVEABLE, sizeof(MODULEENTRY));
142 lpNewMod = (LPMODULEENTRY) GlobalLock(hModule);
144 printf("LoadLibrary // creating new module entry %08X\n", lpNewMod);
146 if (lpNewMod == NULL)
148 if (lpModList == NULL)
150 lpModList = lpNewMod;
151 lpNewMod->lpPrevModule = NULL;
155 lpMod->lpNextModule = lpNewMod;
156 lpNewMod->lpPrevModule = lpMod;
159 lpNewMod->lpNextModule = NULL;
160 lpNewMod->hModule = hModule;
161 lpNewMod->ModuleName = NULL;
162 lpNewMod->FileName = (LPSTR) malloc(strlen(libname));
163 if (lpNewMod->FileName != NULL)
164 strcpy(lpNewMod->FileName, libname);
165 lpNewMod->hInst = LoadImage(libname, DLL);
167 printf("LoadLibrary returned Library hInst=%04X\n", lpNewMod->hInst);
168 GlobalUnlock(hModule);
169 return lpNewMod->hInst;
173 /**********************************************************************
174 * FreeLibrary [KERNEL.96]
176 void FreeLibrary(HANDLE hLib)
178 LPMODULEENTRY lpMod = lpModList;
179 printf("FreeLibrary(%04X);\n", hLib);
180 while (lpMod != NULL) {
181 if (lpMod->hInst == hLib) {
182 if (lpMod->Count == 1) {
183 if (hLib != (HANDLE)NULL) GlobalFree(hLib);
184 if (lpMod->ModuleName != NULL) free(lpMod->ModuleName);
185 if (lpMod->FileName != NULL) free(lpMod->FileName);
186 GlobalFree(lpMod->hModule);
187 printf("FreeLibrary // freed !\n");
191 printf("FreeLibrary // Count decremented !\n");
194 lpMod = lpMod->lpNextModule;
199 /**********************************************************************
200 * GetProcAddress [KERNEL.50]
202 FARPROC GetProcAddress(HANDLE hModule, char *proc_name)
206 register struct w_files *w = wine_files;
212 if (hModule >= 0xF000) {
213 if ((int) proc_name & 0xffff0000) {
214 printf("GetProcAddress: builtin %#04X, '%s'\n",
216 /* wOrdin = FindOrdinalFromName(struct dll_table_entry_s *dll_table, proc_name); */
219 printf("GetProcAddress: builtin %#04X, %d\n",
220 hModule, (int)proc_name);
225 hTask = GetCurrentTask();
226 printf("GetProcAddress // GetCurrentTask()=%04X\n", hTask);
227 lpTask = (LPTASKENTRY) GlobalLock(hTask);
228 if (lpTask == NULL) {
229 printf("GetProcAddress: can't find current module handle !\n");
232 hModule = lpTask->hInst;
233 printf("GetProcAddress: current module=%04X instance=%04X!\n",
234 lpTask->hModule, lpTask->hInst);
237 while (w && w->hinstance != hModule) w = w->next;
238 if (w == NULL) return NULL;
239 printf("GetProcAddress // Module Found ! w->filename='%s'\n", w->filename);
240 if ((int)proc_name & 0xFFFF0000) {
241 AnsiUpper(proc_name);
242 printf("GetProcAddress: %04X, '%s'\n", hModule, proc_name);
243 cpnt = w->nrname_table;
245 if (((int) cpnt) - ((int)w->nrname_table) >
246 w->ne_header->nrname_tab_length) return NULL;
248 strncpy(C, cpnt, len);
251 printf("pointing Function '%s' ordinal=%d !\n",
252 C, *((unsigned short *)(cpnt + len)));
254 if (strncmp(cpnt, proc_name, len) == 0) {
255 ordinal = *((unsigned short *)(cpnt + len));
261 printf("GetProcAddress // function '%s' not found !\n", proc_name);
266 printf("GetProcAddress: %#04x, %d\n", hModule, (int) proc_name);
267 ordinal = (int)proc_name;
269 ret = GetEntryPointFromOrdinal(w, ordinal);
271 printf("GetProcAddress // Function #%d not found !\n", ordinal);
276 printf("GetProcAddress // ret=%08X sel=%04X addr=%04X\n", ret, sel, addr);
277 return (FARPROC) ret;
280 #endif /* ifndef WINELIB */