Annotation of mstools/samples/midimon/instdata.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * instdata.c - Functions to allocate and free the instance
        !             3:  *      data structure passed to the low-level callback function.
        !             4:  */
        !             5: 
        !             6: #include <windows.h>
        !             7: #include <mmsystem.h>
        !             8: #include "midimon.h"
        !             9: #include "circbuf.h"
        !            10: #include "instdata.h"
        !            11: 
        !            12: /* AllocCallbackInstanceData - Allocates a CALLBACKINSTANCEDATA
        !            13:  *      structure.  This structure is used to pass information to the
        !            14:  *      low-level callback function, each time it receives a message.
        !            15:  *
        !            16:  *      Because this structure is accessed by the low-level callback
        !            17:  *      function, it must be allocated using GlobalAlloc() with the 
        !            18:  *      GMEM_SHARE and GMEM_MOVEABLE flags and page-locked with
        !            19:  *      GlobalPageLock().
        !            20:  *
        !            21:  * Params:  void
        !            22:  *
        !            23:  * Return:  A pointer to the allocated CALLBACKINSTANCE data structure.
        !            24:  */
        !            25: LPCALLBACKINSTANCEDATA FAR PASCAL AllocCallbackInstanceData(void)
        !            26: {
        !            27:     HANDLE hMem;
        !            28:     LPCALLBACKINSTANCEDATA lpBuf;
        !            29:     
        !            30:     /* Allocate and lock global memory.
        !            31:      */
        !            32:     hMem = GlobalAlloc(GMEM_SHARE | GMEM_MOVEABLE,
        !            33:                        (DWORD)sizeof(CALLBACKINSTANCEDATA));
        !            34:     if(hMem == NULL)
        !            35:         return NULL;
        !            36:     
        !            37:     lpBuf = (LPCALLBACKINSTANCEDATA)GlobalLock(hMem);
        !            38:     if(lpBuf == NULL){
        !            39:         GlobalFree(hMem);
        !            40:         return NULL;
        !            41:     }
        !            42:     
        !            43:     /* Page lock the memory.
        !            44:      */
        !            45:     //GlobalPageLock((HGLOBAL)HIWORD(lpBuf));
        !            46: 
        !            47:     /* Save the handle.
        !            48:      */
        !            49:     lpBuf->hSelf = hMem;
        !            50: 
        !            51:     return lpBuf;
        !            52: }
        !            53: 
        !            54: /* FreeCallbackInstanceData - Frees the given CALLBACKINSTANCEDATA structure.
        !            55:  *
        !            56:  * Params:  lpBuf - Points to the CALLBACKINSTANCEDATA structure to be freed.
        !            57:  *
        !            58:  * Return:  void
        !            59:  */
        !            60: void FAR PASCAL FreeCallbackInstanceData(LPCALLBACKINSTANCEDATA lpBuf)
        !            61: {
        !            62:     HANDLE hMem;
        !            63: 
        !            64:     /* Save the handle until we're through here.
        !            65:      */
        !            66:     hMem = lpBuf->hSelf;
        !            67: 
        !            68:     /* Free the structure.
        !            69:      */
        !            70:     //GlobalPageUnlock((HGLOBAL)HIWORD(lpBuf));
        !            71:     GlobalUnlock(hMem);
        !            72:     GlobalFree(hMem);
        !            73: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.