home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 11 / 11.iso / m / m248 / 4.ddi / AWITOOLS.C_ / AWITOOLS.C
Encoding:
C/C++ Source or Header  |  1993-02-01  |  6.5 KB  |  313 lines

  1. /* 
  2.  
  3.     AWITOOLS.C -- Sample User Code for Authorware Professional for Windows.
  4.     Copyright 1987-1991 Authorware Inc.
  5.  
  6.     Revision History
  7.  
  8.         7/25/91    -    Initial version
  9.  
  10.     General notes:
  11.  
  12.         The functions in the dll are intended to allow access to global blocks
  13.         of memory from inside APW. All pointers passed into these functions 
  14.         must have been created using the GlobalAlloc function and locked
  15.         using the GlobalLock function.
  16.  
  17.  
  18.         All pointers used are huge pointers to accomidate > 64K blocks.
  19. */                        
  20.  
  21. typedef double    REAL;
  22. typedef unsigned long ULONG;
  23. typedef unsigned char UCHAR;
  24.  
  25. #include <stdlib.h>
  26. #include <string.h>
  27.  
  28. #ifdef NULL
  29. #undef NULL
  30. #endif
  31.  
  32. #include "windows.h"
  33.  
  34. short             far pascal WEP( short bSystemExit );
  35. short                far pascal LibMain( HANDLE hModule, WORD wDataSeg, WORD cbHeapSize, LPSTR lpszCmdLine );
  36.  
  37. short    far pascal LibMain( HANDLE hModule, WORD wDataSeg, WORD cbHeapSize, 
  38.                                         LPSTR lpszCmdLine )
  39.  
  40. /*
  41.     Is called by LibEntry.  LibEntry is called by Windows when the DLL is
  42.     loaded.  The LibEntry routine is provided in the LIBENTRY.OBJ in the SDK
  43.     Link Libraries disk.  (The source LIBENTRY.ASM is also provided.)  
  44.  
  45.     LibEntry initializes the DLL's heap, if a HEAPSIZE value is specified
  46.     in the DLL's DEF file.  Then LibEntry calls LibMain.  The LibMain function
  47.     below satisfies that call.
  48.              
  49.     The LibMain function should perform additional initialization tasks
  50.     required by the DLL.  In this example, no initialization tasks are
  51.     required.  LibMain should return a value of 1 if the initialization is
  52.     successful.
  53. */
  54. {
  55.     return 1;
  56. }
  57.  
  58.  
  59. short far pascal WEP( short bSystemExit )
  60. /*
  61.     Performs cleanup tasks when the DLL is unloaded.  WEP() is called
  62.     automatically by Windows when the DLL is unloaded (no remaining tasks
  63.     still have the DLL loaded).  It is strongly recommended that a DLL have a
  64.     WEP() function, even if it does nothing but returns success (1), as in
  65.     this example.
  66. */
  67. {
  68.     return 1;
  69. }
  70.  
  71.  
  72. void far pascal PokeByte( char huge *destination, long offset, unsigned char new_value )
  73. /*
  74.     Given a far pointer to a destination block of memory put the byte new_value
  75.     at offset.
  76.  
  77.     Returns:
  78.  
  79.         Void
  80. */
  81. {
  82.     destination[offset] = new_value;
  83. }
  84.  
  85.  
  86. char far pascal PeekByte( char huge *source, long offset )
  87. /*
  88.     Given a far pointer to a source block of memory return the byte
  89.     at offset.
  90.  
  91.     Returns:
  92.  
  93.         Void
  94. */
  95. {
  96.     return (char)source[offset];
  97. }
  98.  
  99.  
  100. unsigned char far pascal PeekUByte( char huge *source, long offset )
  101. /*
  102.     Given a far pointer to a source block of memory return the unsigned 
  103.     byte at offset.
  104.  
  105.     Returns:
  106.  
  107.         unsigned byte found at offset in source.
  108. */
  109. {
  110.     return (unsigned char)source[offset];
  111. }
  112.  
  113.  
  114. void far pascal PokeUShort( char huge *destination, long offset, short new_value )
  115. /*
  116.     Given a far pointer to a destination block of memory put the unsigned short
  117.     new_value at offset.
  118.  
  119.     Returns:
  120.         
  121.         Void
  122. */
  123. {
  124.     (unsigned short)(destination[offset]) = new_value;
  125. }
  126.  
  127.  
  128. unsigned short far pascal PeekUShort( char huge *source, long offset )
  129. /*
  130.     Given a far pointer to a source block of memory return the unsigned 
  131.     short at offset.
  132.  
  133.     Returns:
  134.  
  135.         unsigned short found at offset in source.
  136. */
  137. {
  138.     source += offset;
  139.     return *(unsigned short huge *)source;
  140. }
  141.  
  142.  
  143. short far pascal PeekShort( char huge *source, long offset )
  144. /*
  145.     Given a far pointer to a source block of memory return the signed 
  146.     short at offset.
  147.  
  148.     Returns:
  149.  
  150.         short found at offset in source.
  151. */
  152. {    
  153.     source += offset;
  154.     return *(short huge *)source;
  155. }
  156.  
  157.  
  158. void far pascal PokeULong( char huge *destination, long offset, long new_value )
  159. /*
  160.     Given a far pointer to a destination block of memory put the long new_value
  161.     at offset.
  162.  
  163.     Returns:
  164.  
  165.         Void
  166. */
  167. {
  168.     (unsigned long)(destination[offset]) = new_value;
  169. }
  170.  
  171.  
  172. unsigned long far pascal PeekULong( char huge *source, long offset )
  173. /*
  174.     Given a far pointer to a source block of memory return the unsigned long
  175.     value at offset.
  176.  
  177.     Returns:
  178.  
  179.         unsigned long found at offset in source.
  180. */
  181. {
  182.     source += offset;
  183.     return *(unsigned long huge *)source;
  184. }
  185.  
  186.  
  187. long far pascal PeekLong( char huge *source, long offset )
  188. /*
  189.     Given a far pointer to a source block of memory return the signed long 
  190.     at offset.
  191.  
  192.     Returns:
  193.  
  194.         long found at offset in source.
  195. */
  196. {
  197.     source += offset;
  198.     return *(long huge *)source;
  199. }
  200.  
  201.  
  202. void far pascal PokeFloat( char huge *destination, long offset, float new_value )
  203. /*
  204.     Given a far pointer to a destination block of memory put the float new_value
  205.     at offset.
  206.  
  207.     Returns:
  208.  
  209.         Void
  210. */
  211. {
  212.     (float)(destination[offset]) = new_value;
  213. }
  214.  
  215.  
  216. float far pascal PeekFloat( char huge *source, long offset )
  217. /*
  218.     Given a far pointer to a source block of memory return the float value
  219.     at offset.
  220.  
  221.     Returns:
  222.  
  223.         float found at offset in source.
  224. */
  225. {
  226.     source += offset;
  227.     return *(float huge *)source;
  228. }
  229.  
  230.  
  231. void far pascal PokeDouble( char huge *destination, long offset, double new_value )
  232. /*
  233.     Given a far pointer to a destination block of memory put the double 
  234.     new_value at offset.
  235.  
  236.     Returns:
  237.         
  238.         Void
  239. */
  240. {
  241.     (double)(destination[offset]) = new_value;
  242. }
  243.  
  244.  
  245. double far pascal PeekDouble( char huge *source, long offset )
  246. /*
  247.     Given a far pointer to a source block of memory return the double value
  248.     at offset.
  249.  
  250.     Returns:
  251.  
  252.         double found at offset in source.
  253. */
  254. {
  255.     source += offset;
  256.     return *(double huge *)source;
  257. }
  258.  
  259.  
  260. void far pascal PokeString( char huge *destination, long offset, char huge *new_value )
  261. /*
  262.     Given a far pointer to a destination string copy the passed zero terminated
  263.     string new_value into the destination string at offset.
  264.  
  265.     Returns:
  266.  
  267.         Void
  268. */
  269. {
  270.     char    huge *dest;
  271.  
  272.     dest = destination+offset;
  273.     while (*dest++ = *new_value++);
  274. }
  275.  
  276.  
  277. HANDLE far pascal PeekString( char huge *source, long offset )
  278. /*
  279.     Given a far pointer to a source block of memory return the zero terminated
  280.     string at offset.
  281.  
  282.     Returns:
  283.  
  284.         Handle to a global block of memory containing the string.
  285.         0 - Insufficient memory.
  286. */
  287. {
  288.     HANDLE    h;
  289.     LPSTR        v;
  290.     long        len;
  291.     char        huge *ptr;
  292.  
  293.     // Find the length of the string - use huge pointers for large blocks
  294.     // of memory.
  295.     ptr = source+offset;
  296.     for (len=1; *ptr; ++ptr, ++len);
  297.  
  298.     // GlobalAlloc a copy of the string and return a copy.
  299.     // Caller is responsible for deleting the allocation.
  300.     if ((h = GlobalAlloc(GHND,len)))
  301.     {
  302.         // Copy in the string.
  303.         v = GlobalLock(h);
  304.         ptr = &source[offset];
  305.         while (*v++ = *ptr++);
  306.         GlobalUnlock(h);
  307.  
  308.     }
  309.  
  310.     return h;
  311. }
  312.  
  313.