home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 267.img / RESIDNTC.ZIP / DEMOS.ZIP / SHAREFOR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-13  |  2.6 KB  |  81 lines

  1. /*
  2.       Module name.
  3.           sharefor.c - works with sharetsr.c
  4.           This program will access the shared structure in sharetsr.c
  5.             and print the system time as built by sharetsr.
  6.   
  7.         It will access the structure two ways, first by using findsig()
  8.             and second by using tsrshare().
  9.   
  10.         It prompts for a 'F' to free the TSR to show that data can be
  11.             passed back the other way.  If a 'F' is hit on the keyboard
  12.             the TSR will free itself on the next timer tick that it can.
  13.   
  14. --)   NOTICE:  Copyright (C) 1988 South Mountain Software, Inc.
  15. */
  16.   
  17. #include "stdio.h"
  18. #include "conio.h"
  19. #include "tsr.h"
  20. #include "resproto.h"
  21. #include    "dos.h"
  22.   
  23. struct share{                           /* structure to share with foreground program */
  24. unsigned my_sig;            /* signature placed here for find_sig() example */
  25. char time_str[30];      /* time of day string placed here */
  26. long a_key_hit;             /* count of key presses and releases */
  27. long dos_calls;         /* count of int 21H calls */
  28. long chars_printed;         /* number of characters printed */
  29. } ;
  30.   
  31. void main(void)
  32. {
  33. struct share far *share_ptr;    /* struct pointer found by findsig() */
  34. struct share far *retptr;       /* struct pointer returned by tsrshare() */
  35. unsigned sig = 0xdcba;          /* signature to search for */
  36. int i,j;
  37. char far *temp_ptr;
  38. char   local_str[30];           /* local string space */
  39.   
  40. i = find_sig(0x60,0x67,sig,(void far *)&share_ptr);
  41. if(i)
  42.     {
  43.     printf("Found signature at %xHEX.  Ptr = <%p>\n",i,share_ptr);
  44.     temp_ptr =  (char far *) share_ptr;
  45.     temp_ptr += 2;                /* point to struct time string */
  46.     j=0;
  47.     while(*temp_ptr++ != '\0')      /* copy time string to local_str */
  48.         {
  49.         local_str[j++] = *temp_ptr;
  50.         }
  51.     local_str[j] = '\0';
  52.     printf("String time in sharetsr = <%s> \n",local_str);
  53.     }
  54. else
  55.     {
  56.     printf("Signature not found!");
  57.     }
  58.   
  59.   
  60. i = tsrshare(0x5272,(void far *)&retptr);
  61. printf("return from tsrshare() = %d    far pointer retptr = <%p>\n",i,retptr);
  62. printf("retptr->my_sig = %x\n", retptr->my_sig);
  63. printf("retptr->time_str = %Fs\n",retptr->time_str);
  64. printf("retptr->a_key_hit = %ld\n",retptr->a_key_hit);
  65. printf("retptr->dos_cd_calls = %ld\n",retptr->dos_calls);
  66. printf("retptr->chars_printed = %ld\n",retptr->chars_printed);
  67.   
  68.   
  69.   
  70. printf("\n\n enter 'F' to free the tsr or anything else not to free it\n");
  71. j = getch();
  72. if(j == 'F' || j == 'f')
  73.     {
  74.     j = tsrfree(0x5272,1);
  75.     if(j != 0)
  76.         printf("error in tsrfree = %d\n",j);
  77.     }
  78.   
  79. }
  80.   
  81.