Subversion Repositories Kolibri OS

Rev

Rev 539 | Go to most recent revision | Blame | 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 <kolibrisys.h>
  7.  
  8. char* dllname="/sys/lib/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)(const char* string);
  18. void cdecl  (* con_printf)(const char* format,...);
  19. void stdcall (* con_exit)(dword bCloseWindow);
  20.  
  21. struct import{
  22.         char *name;
  23.         void *data;
  24. };
  25.  
  26. void link(struct import *exp, char** imports){
  27.         dll_start = (dword (*)(dword))
  28.                 _ksys_cofflib_getproc(exp, imports[0]);
  29.         dll_ver = (dword*)
  30.                 _ksys_cofflib_getproc(exp, imports[1]);
  31.         con_init = (void stdcall (*)(dword , dword, dword, dword, const char*))
  32.                 _ksys_cofflib_getproc(exp, imports[2]);
  33.         con_write_asciiz = (void stdcall (*)(const char*))
  34.                 _ksys_cofflib_getproc(exp, imports[3]);
  35.         con_printf = (void cdecl (*)(const char*,...))
  36.                 _ksys_cofflib_getproc(exp, imports[4]);
  37.         con_exit = (void stdcall (*)(dword))
  38.                 _ksys_cofflib_getproc(exp, imports[5]);
  39. }
  40.  
  41. int main(int argc, char **argv){
  42.  
  43.         struct import * hDll;
  44.         int a,b,c,d;
  45.  
  46.         if((hDll = (struct import *)_ksys_cofflib_load(dllname)) == 0){
  47.                 debug_out_str("can't load lib\n");
  48.                 return 1;
  49.         }
  50.         link(hDll, imports);
  51.         debug_out_str("dll loaded\n");
  52.  
  53.         if(dll_start(1) == 0){
  54.                 debug_out_str("dll_start failed\n");
  55.                 return 1;
  56.         }
  57.  
  58.         con_init(-1, -1, -1, -1, caption);
  59.  
  60.         for(i = 0; i < 256; i++){
  61.                 con_printf("Color 0x%02X: ", i);
  62.                 con_write_asciiz("Text sample.");
  63.  
  64.                 con_printf("  printf %s test %d\n", "small", i);
  65.  
  66.         }
  67.  
  68.         con_exit(0);
  69.         debug_out_str("all right's ;)\n");
  70. }