Subversion Repositories Kolibri OS

Rev

Rev 539 | Go to most recent revision | Show entire file | Regard 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]);
-
 
34
        con_printf = (void cdecl (*)(const char*,...))
42
	con_printf = (void cdecl (*)(dword, const char*, ...))
35
                _ksys_cofflib_getproc(exp, imports[4]);
-
 
36
        con_exit = (void stdcall (*)(dword))
Line 43... Line 37...
43
		__msys_cofflib_getproc(exp, imports[4]);
37
                _ksys_cofflib_getproc(exp, imports[5]);
44
	con_exit = (void stdcall (*)(dword))
38
}
45
		__msys_cofflib_getproc(exp, imports[5]);
39
 
46
}
40
int main(int argc, char **argv){
47
 
41
 
48
int main(int argc, char **argv){
42
        struct import * hDll;
Line 49... Line 43...
49
	struct import * hDll;
43
        int a,b,c,d;
50
 
44
 
51
	if((hDll = (struct import *)_msys_cofflib_load(dllname)) == 0){
45
        if((hDll = (struct import *)_ksys_cofflib_load(dllname)) == 0){
52
		debug_out_str("can't load lib\n\r");
46
                debug_out_str("can't load lib\n");
Line 53... Line 47...
53
		return 1;
47
                return 1;
-
 
48
        }
54
	}
49
        link(hDll, imports);
55
	link(hDll, imports);
50
        debug_out_str("dll loaded\n");
56
        debug_out_str("dll loaded\n\r");
51
 
-
 
52
        if(dll_start(1) == 0){
-
 
53
                debug_out_str("dll_start failed\n");
Line 57... Line -...
57
 
-
 
58
	if(dll_start(1) == 0){
54
                return 1;
Line 59... Line 55...
59
		debug_out_str("dll_start failed\n\r");
55
        }
60
		return 1;
56
 
61
        }
57
        con_init(-1, -1, -1, -1, caption);
62
 
58