Rev 539 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 539 | Rev 647 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | // Console dynamic link library. Sample by Ghost |
1 | // Console dynamic link library. Sample by Ghost |
Line 2... | Line 2... | ||
2 | 2 | ||
3 | #include "stdio.h" |
3 | #include |
4 | #include "string.h" |
4 | #include |
Line 5... | Line 5... | ||
5 | #include "mesys.h" |
5 | #include |
6 | 6 | ||
Line 7... | Line 7... | ||
7 | char* dllname="/sys/console.obj"; |
7 | char* dllname="/sys/lib/console.obj"; |
8 | int i; |
8 | int i; |
Line 9... | Line 9... | ||
9 | 9 | ||
10 | char* imports[] = {"START","version","con_init","con_write_asciiz","con_printf","con_exit",NULL}; |
10 | char* imports[] = {"START","version","con_init","con_write_asciiz","con_printf","con_exit",NULL}; |
11 | char* caption = "Console test - colors"; |
11 | char* caption = "Console test - colors"; |
12 | 12 | ||
13 | dword (* dll_start)(dword res); |
13 | dword (* dll_start)(dword res); |
14 | dword* dll_ver; |
14 | dword* dll_ver; |
Line 15... | Line 15... | ||
15 | void stdcall (* con_init)(dword wnd_width, dword wnd_height, dword scr_width, dword scr_height, const char* title); |
15 | void stdcall (* con_init)(dword wnd_width, dword wnd_height, dword scr_width, dword scr_height, const char* title); |
16 | void stdcall (* con_write_asciiz)(dword flags, const char* string); |
16 | void stdcall (* con_write_asciiz)(const char* string); |
17 | void cdecl (* con_printf)(dword flags, const char* format, ...); |
17 | void cdecl (* con_printf)(const char* format,...); |
18 | void stdcall (* con_exit)(dword bCloseWindow); |
18 | void stdcall (* con_exit)(dword bCloseWindow); |
Line 19... | Line -... | ||
19 | - | ||
20 | struct import{ |
- | |
21 | char *name; |
- | |
22 | void *data; |
- | |
23 | }; |
- | |
24 | - | ||
25 | // â áèáëèîòåêå åñòü àíàëîãè÷íàÿ ôóíêöèÿ _msys_cofflib_getproc, íî ïîêà îíà ðàáîòàåò íå êîððåêòíî |
- | |
26 | void* __msys_cofflib_getproc(struct import *lib, char *name){ |
- | |
27 | int i; |
19 | |
28 | for(i = 0; lib[i].name && strcmp(name, lib[i].name); i++); |
20 | struct import{ |
29 | if(lib[i].name)return lib[i].data; |
21 | char *name; |
30 | else return NULL; |
22 | void *data; |
31 | } |
23 | }; |
32 | 24 | ||
33 | void link(struct import *exp, char** imports){ |
25 | void link(struct import *exp, char** imports){ |
34 | dll_start = (dword (*)(dword)) |
26 | dll_start = (dword (*)(dword)) |
35 | __msys_cofflib_getproc(exp, imports[0]); |
27 | _ksys_cofflib_getproc(exp, imports[0]); |
36 | dll_ver = (dword*) |
28 | dll_ver = (dword*) |
37 | __msys_cofflib_getproc(exp, imports[1]); |
29 | _ksys_cofflib_getproc(exp, imports[1]); |
38 | con_init = (void stdcall (*)(dword , dword, dword, dword, const char*)) |
30 | con_init = (void stdcall (*)(dword , dword, dword, dword, const char*)) |
39 | __msys_cofflib_getproc(exp, imports[2]); |
31 | _ksys_cofflib_getproc(exp, imports[2]); |
40 | con_write_asciiz = (void stdcall (*)(dword, const char*)) |
32 | con_write_asciiz = (void stdcall (*)(const char*)) |
Line 41... | Line 33... | ||
41 | __msys_cofflib_getproc(exp, imports[3]); |
33 | _ksys_cofflib_getproc(exp, imports[3]); |
42 | con_printf = (void cdecl (*)(dword, const char*, ...)) |
- | |
Line 43... | Line -... | ||
43 | __msys_cofflib_getproc(exp, imports[4]); |
- | |
44 | con_exit = (void stdcall (*)(dword)) |
- | |
45 | __msys_cofflib_getproc(exp, imports[5]); |
- | |
46 | } |
- | |
47 | 34 | con_printf = (void cdecl (*)(const char*,...)) |
|
48 | int main(int argc, char **argv){ |
35 | _ksys_cofflib_getproc(exp, imports[4]); |
49 | struct import * hDll; |
36 | con_exit = (void stdcall (*)(dword)) |
50 | 37 | _ksys_cofflib_getproc(exp, imports[5]); |
|
51 | if((hDll = (struct import *)_msys_cofflib_load(dllname)) == 0){ |
38 | } |
52 | debug_out_str("can't load lib\n\r"); |
39 | |
53 | return 1; |
40 | int main(int argc, char **argv){ |
- | 41 | ||
- | 42 | struct import * hDll; |
|
- | 43 | int a,b,c,d; |
|
- | 44 | ||
- | 45 | if((hDll = (struct import *)_ksys_cofflib_load(dllname)) == 0){ |
|
- | 46 | debug_out_str("can't load lib\n"); |
|
- | 47 | return 1; |
|
- | 48 | } |
|
- | 49 | link(hDll, imports); |
|
- | 50 | debug_out_str("dll loaded\n"); |
|
- | 51 | ||
- | 52 | if(dll_start(1) == 0){ |
|
- | 53 | debug_out_str("dll_start failed\n"); |
|
Line 54... | Line -... | ||
54 | } |
- | |
55 | link(hDll, imports); |
- | |
56 | debug_out_str("dll loaded\n\r"); |
54 | return 1; |
57 | - | ||
Line 58... | Line -... | ||
58 | if(dll_start(1) == 0){ |
- | |
59 | debug_out_str("dll_start failed\n\r"); |
55 | } |
Line 60... | Line 56... | ||
60 | return 1; |
56 | |
61 | } |
57 | con_init(-1, -1, -1, -1, caption); |
62 | 58 | ||
63 | con_init(-1, -1, -1, -1, caption); |
59 | for(i = 0; i < 256; i++){ |