Subversion Repositories Kolibri OS

Rev

Rev 249 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1.  
  2. // Console dynamic link library. Sample by Ghost
  3.  
  4. #include "stdio.h"
  5. #include "string.h"
  6. #include "mesys.h"
  7.  
  8. char* dllname="/sys/console.obj";
  9. int i;
  10.  
  11. char* imports[] = {"START","version","con_init","con_write_asciiz","con_printf","con_exit",NULL};
  12. char* caption = "Console test - colors";
  13.  
  14. dword (* dll_start)(dword res);
  15. dword* dll_ver;
  16. void stdcall (* con_init)(dword wnd_width, dword wnd_height, dword scr_width, dword scr_height, const char* title);
  17. void stdcall (* con_write_asciiz)(dword flags, const char* string);
  18. void cdecl (* con_printf)(dword flags, const char* format, ...);
  19. void stdcall (* con_exit)(dword bCloseWindow);
  20.  
  21. struct import{
  22.         char *name;
  23.         void *data;
  24. };
  25.  
  26. // т сшсышюЄхъх хёЄ№ рэрыюушўэр  ЇєэъЎш  _msys_cofflib_getproc, эю яюър юэр ЁрсюЄрхЄ эх ъюЁЁхъЄэю
  27. void* __msys_cofflib_getproc(struct import *lib, char *name){
  28.         int i;
  29.         for(i = 0; lib[i].name && strcmp(name, lib[i].name); i++);
  30.         if(lib[i].name)return lib[i].data;
  31.         else return NULL;
  32. }
  33.  
  34. void link(struct import *exp, char** imports){
  35.         dll_start = (dword (*)(dword))
  36.                 __msys_cofflib_getproc(exp, imports[0]);
  37.         dll_ver = (dword*)
  38.                 __msys_cofflib_getproc(exp, imports[1]);
  39.         con_init = (void stdcall (*)(dword , dword, dword, dword, const char*))
  40.                 __msys_cofflib_getproc(exp, imports[2]);
  41.         con_write_asciiz = (void stdcall (*)(dword, const char*))
  42.                 __msys_cofflib_getproc(exp, imports[3]);
  43.         con_printf = (void cdecl (*)(dword, const char*, ...))
  44.                 __msys_cofflib_getproc(exp, imports[4]);
  45.         con_exit = (void stdcall (*)(dword))
  46.                 __msys_cofflib_getproc(exp, imports[5]);
  47. }
  48.  
  49. int main(int argc, char **argv){
  50.         struct import * hDll;
  51.  
  52.         if((hDll = (struct import *)_msys_cofflib_load(dllname)) == 0){
  53.                 debug_out_str("can't load lib\n\r");
  54.                 return 1;
  55.         }
  56.         link(hDll, imports);
  57.         debug_out_str("dll loaded\n\r");
  58.  
  59.         if(dll_start(1) == 0){
  60.                 debug_out_str("dll_start failed\n\r");
  61.                 return 1;
  62.         }
  63.  
  64.         con_init(-1, -1, -1, -1, caption);
  65.         for(i = 0; i < 256; i++){
  66.                 con_printf(7, "Color 0x%02X: ", i);
  67.                 con_write_asciiz(i, "Text sample.");
  68.  
  69.                 con_printf(i, "  printf %s test %d\n", "small", i);
  70.         }
  71.  
  72.         con_exit(0);
  73.         debug_out_str("all right's ;)\n\r");
  74. }