Release 940405
[wine/gsoc-2012-control.git] / loader / library.c
blob39ea0bba1bbde514b17e3ac0e854f260606fc488
1 #ifndef WINELIB
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include <sys/types.h>
6 #include <sys/stat.h>
7 #include <fcntl.h>
8 #include <unistd.h>
9 #include "prototypes.h"
10 #include "windows.h"
11 #include "wine.h"
12 #include "dlls.h"
14 typedef struct module_table_entry
16 HINSTANCE hInst;
17 LPSTR name;
18 WORD count;
19 } MODULEENTRY;
21 extern struct w_files * wine_files;
23 #define N_BUILTINS 10
25 extern struct dll_name_table_entry_s dll_builtin_table[N_BUILTINS];
27 /**********************************************************************
28 * GetCurrentTask [KERNEL.36]
30 HTASK GetCurrentTask()
32 int pid = getpid();
33 printf("GetCurrentTask() returned %d !\n", pid);
34 return pid;
38 /**********************************************************************
39 * GetModuleHandle [KERNEL.47]
41 HANDLE GetModuleHandle(LPSTR lpModuleName)
43 register struct w_files *w = wine_files;
44 int i;
45 printf("GetModuleHandle('%s');\n", lpModuleName);
46 while (w) {
47 /* printf("GetModuleHandle // '%s' \n", w->name); */
48 if (strcmp(w->name, lpModuleName) == 0) {
49 printf("GetModuleHandle('%s') return %04X \n",
50 lpModuleName, w->hinstance);
51 return w->hinstance;
53 w = w->next;
55 for (i = 0; i < N_BUILTINS; i++) {
56 if (strcmp(dll_builtin_table[i].dll_name, lpModuleName) == 0) {
57 printf("GetModuleHandle('%s') return %04X \n",
58 lpModuleName, 0xFF00 + i);
59 return (0xFF00 + i);
62 printf("GetModuleHandle('%s') not found !\n", lpModuleName);
63 return 0;
67 /**********************************************************************
68 * GetModuleUsage [KERNEL.48]
70 int GetModuleUsage(HANDLE hModule)
72 struct w_files *w;
73 printf("GetModuleUsage(%04X);\n", hModule);
74 w = GetFileInfo(hModule);
75 /* return w->Usage; */
76 return 1;
80 /**********************************************************************
81 * GetModuleFilename [KERNEL.49]
83 int GetModuleFileName(HANDLE hModule, LPSTR lpFileName, short nSize)
85 struct w_files *w;
86 printf("GetModuleFileName(%04X, %08X, %d);\n", hModule, lpFileName, nSize);
87 if (lpFileName == NULL) return 0;
88 w = GetFileInfo(hModule);
89 if (w == NULL) return 0;
90 if (nSize > strlen(w->name)) nSize = strlen(w->name) + 1;
91 strncpy(lpFileName, w->name, nSize);
92 printf("GetModuleFileName copied '%s' return %d \n", lpFileName, nSize);
93 return nSize - 1;
97 /**********************************************************************
98 * LoadLibrary [KERNEL.95]
100 HANDLE LoadLibrary(LPSTR libname)
102 HANDLE hModule;
103 printf("LoadLibrary '%s'\n", libname);
104 hModule = LoadImage(libname, DLL);
105 printf("LoadLibrary returned hModule=%04X\n", hModule);
106 return hModule;
110 /**********************************************************************
111 * FreeLibrary [KERNEL.96]
113 void FreeLibrary(HANDLE hLib)
115 printf("FreeLibrary(%04X);\n", hLib);
116 if (hLib != (HANDLE)NULL) GlobalFree(hLib);
120 /**********************************************************************
121 * GetProcAddress [KERNEL.50]
123 FARPROC GetProcAddress(HANDLE hModule, char *proc_name)
125 WORD wOrdin;
126 int sel, addr, ret;
127 register struct w_files *w = wine_files;
128 int ordinal, len;
129 char * cpnt;
130 char C[128];
131 if (hModule == 0) {
132 printf("GetProcAddress: Bad Module handle=%#04X\n", hModule);
133 return NULL;
135 if (hModule >= 0xF000) {
136 if ((int) proc_name & 0xffff0000) {
137 printf("GetProcAddress: builtin %#04x, '%s'\n", hModule, proc_name);
138 /* wOrdin = FindOrdinalFromName(struct dll_table_entry_s *dll_table, proc_name); */
140 else {
141 printf("GetProcAddress: builtin %#04x, %d\n", hModule, (int) proc_name);
143 return NULL;
145 while (w && w->hinstance != hModule) w = w->next;
146 printf("GetProcAddress // Module Found ! w->filename='%s'\n", w->filename);
147 if (w == NULL) return NULL;
148 if ((int) proc_name & 0xffff0000) {
149 AnsiUpper(proc_name);
150 printf("GetProcAddress: %#04x, '%s'\n", hModule, proc_name);
151 cpnt = w->nrname_table;
152 while(TRUE) {
153 if (((int) cpnt) - ((int)w->nrname_table) >
154 w->ne_header->nrname_tab_length) return NULL;
155 len = *cpnt++;
156 strncpy(C, cpnt, len);
157 C[len] = '\0';
158 printf("pointing Function '%s' !\n", C);
159 if (strncmp(cpnt, proc_name, len) == 0) break;
160 cpnt += len + 2;
162 ordinal = *((unsigned short *) (cpnt + len));
164 else {
165 printf("GetProcAddress: %#04x, %d\n", hModule, (int) proc_name);
166 ordinal = (int)proc_name;
168 ret = GetEntryPointFromOrdinal(w, ordinal);
169 if (ret == -1) {
170 printf("GetProcAddress // Function not found !\n");
171 return NULL;
173 addr = ret & 0xffff;
174 sel = (ret >> 16);
175 printf("GetProcAddress // ret=%08X sel=%04X addr=%04X\n", ret, sel, addr);
176 return ret;
179 #endif /* ifndef WINELIB */