home *** CD-ROM | disk | FTP | other *** search
- /*
-
- AWITOOLS.C -- Sample User Code for Authorware Professional for Windows.
- Copyright 1987-1991 Authorware Inc.
-
- Revision History
-
- 7/25/91 - Initial version
-
- General notes:
-
- The functions in the dll are intended to allow access to global blocks
- of memory from inside APW. All pointers passed into these functions
- must have been created using the GlobalAlloc function and locked
- using the GlobalLock function.
-
-
- All pointers used are huge pointers to accomidate > 64K blocks.
- */
-
- typedef double REAL;
- typedef unsigned long ULONG;
- typedef unsigned char UCHAR;
-
- #include <stdlib.h>
- #include <string.h>
-
- #ifdef NULL
- #undef NULL
- #endif
-
- #include "windows.h"
-
- short far pascal WEP( short bSystemExit );
- short far pascal LibMain( HANDLE hModule, WORD wDataSeg, WORD cbHeapSize, LPSTR lpszCmdLine );
-
- short far pascal LibMain( HANDLE hModule, WORD wDataSeg, WORD cbHeapSize,
- LPSTR lpszCmdLine )
-
- /*
- Is called by LibEntry. LibEntry is called by Windows when the DLL is
- loaded. The LibEntry routine is provided in the LIBENTRY.OBJ in the SDK
- Link Libraries disk. (The source LIBENTRY.ASM is also provided.)
-
- LibEntry initializes the DLL's heap, if a HEAPSIZE value is specified
- in the DLL's DEF file. Then LibEntry calls LibMain. The LibMain function
- below satisfies that call.
-
- The LibMain function should perform additional initialization tasks
- required by the DLL. In this example, no initialization tasks are
- required. LibMain should return a value of 1 if the initialization is
- successful.
- */
- {
- return 1;
- }
-
-
- short far pascal WEP( short bSystemExit )
- /*
- Performs cleanup tasks when the DLL is unloaded. WEP() is called
- automatically by Windows when the DLL is unloaded (no remaining tasks
- still have the DLL loaded). It is strongly recommended that a DLL have a
- WEP() function, even if it does nothing but returns success (1), as in
- this example.
- */
- {
- return 1;
- }
-
-
- void far pascal PokeByte( char huge *destination, long offset, unsigned char new_value )
- /*
- Given a far pointer to a destination block of memory put the byte new_value
- at offset.
-
- Returns:
-
- Void
- */
- {
- destination[offset] = new_value;
- }
-
-
- char far pascal PeekByte( char huge *source, long offset )
- /*
- Given a far pointer to a source block of memory return the byte
- at offset.
-
- Returns:
-
- Void
- */
- {
- return (char)source[offset];
- }
-
-
- unsigned char far pascal PeekUByte( char huge *source, long offset )
- /*
- Given a far pointer to a source block of memory return the unsigned
- byte at offset.
-
- Returns:
-
- unsigned byte found at offset in source.
- */
- {
- return (unsigned char)source[offset];
- }
-
-
- void far pascal PokeUShort( char huge *destination, long offset, short new_value )
- /*
- Given a far pointer to a destination block of memory put the unsigned short
- new_value at offset.
-
- Returns:
-
- Void
- */
- {
- (unsigned short)(destination[offset]) = new_value;
- }
-
-
- unsigned short far pascal PeekUShort( char huge *source, long offset )
- /*
- Given a far pointer to a source block of memory return the unsigned
- short at offset.
-
- Returns:
-
- unsigned short found at offset in source.
- */
- {
- source += offset;
- return *(unsigned short huge *)source;
- }
-
-
- short far pascal PeekShort( char huge *source, long offset )
- /*
- Given a far pointer to a source block of memory return the signed
- short at offset.
-
- Returns:
-
- short found at offset in source.
- */
- {
- source += offset;
- return *(short huge *)source;
- }
-
-
- void far pascal PokeULong( char huge *destination, long offset, long new_value )
- /*
- Given a far pointer to a destination block of memory put the long new_value
- at offset.
-
- Returns:
-
- Void
- */
- {
- (unsigned long)(destination[offset]) = new_value;
- }
-
-
- unsigned long far pascal PeekULong( char huge *source, long offset )
- /*
- Given a far pointer to a source block of memory return the unsigned long
- value at offset.
-
- Returns:
-
- unsigned long found at offset in source.
- */
- {
- source += offset;
- return *(unsigned long huge *)source;
- }
-
-
- long far pascal PeekLong( char huge *source, long offset )
- /*
- Given a far pointer to a source block of memory return the signed long
- at offset.
-
- Returns:
-
- long found at offset in source.
- */
- {
- source += offset;
- return *(long huge *)source;
- }
-
-
- void far pascal PokeFloat( char huge *destination, long offset, float new_value )
- /*
- Given a far pointer to a destination block of memory put the float new_value
- at offset.
-
- Returns:
-
- Void
- */
- {
- (float)(destination[offset]) = new_value;
- }
-
-
- float far pascal PeekFloat( char huge *source, long offset )
- /*
- Given a far pointer to a source block of memory return the float value
- at offset.
-
- Returns:
-
- float found at offset in source.
- */
- {
- source += offset;
- return *(float huge *)source;
- }
-
-
- void far pascal PokeDouble( char huge *destination, long offset, double new_value )
- /*
- Given a far pointer to a destination block of memory put the double
- new_value at offset.
-
- Returns:
-
- Void
- */
- {
- (double)(destination[offset]) = new_value;
- }
-
-
- double far pascal PeekDouble( char huge *source, long offset )
- /*
- Given a far pointer to a source block of memory return the double value
- at offset.
-
- Returns:
-
- double found at offset in source.
- */
- {
- source += offset;
- return *(double huge *)source;
- }
-
-
- void far pascal PokeString( char huge *destination, long offset, char huge *new_value )
- /*
- Given a far pointer to a destination string copy the passed zero terminated
- string new_value into the destination string at offset.
-
- Returns:
-
- Void
- */
- {
- char huge *dest;
-
- dest = destination+offset;
- while (*dest++ = *new_value++);
- }
-
-
- HANDLE far pascal PeekString( char huge *source, long offset )
- /*
- Given a far pointer to a source block of memory return the zero terminated
- string at offset.
-
- Returns:
-
- Handle to a global block of memory containing the string.
- 0 - Insufficient memory.
- */
- {
- HANDLE h;
- LPSTR v;
- long len;
- char huge *ptr;
-
- // Find the length of the string - use huge pointers for large blocks
- // of memory.
- ptr = source+offset;
- for (len=1; *ptr; ++ptr, ++len);
-
- // GlobalAlloc a copy of the string and return a copy.
- // Caller is responsible for deleting the allocation.
- if ((h = GlobalAlloc(GHND,len)))
- {
- // Copy in the string.
- v = GlobalLock(h);
- ptr = &source[offset];
- while (*v++ = *ptr++);
- GlobalUnlock(h);
-
- }
-
- return h;
- }
-
-