Microsoft KB Archive/31662

GlobalWire and GlobalUnWire and Necessary Input Parameters

PSS ID Number: Q31662 Article last modified on 11-05-1993

2.00 3.00 MS-DOS

= QUESION =

I am confused after reading the documentation for GlobalWire and GlobalUnWire, over what the necessary input parameters are. For these two calls, the documentation describes the hMem variable as follows: “Identifies the segment that will be moved and locked” All other functions that use a hMem refer to GlobalWire and GlobalUnWire as follows: “Identifies the global memory block” Does this mean that GlobalWire and GlobalUnWire need a Segment address?

= RESPONSE =

GlobalWire and GlobalUnWire are newer functions. This probably is the cause of the variation in description of the hMem parameter. Both functions require a ‘HANDLE’ parameter, as do GlobalLock, GlobalUnlock, GlobalSize, and all the other Global Memory functions that utilize ‘hMem’ values. An example of code that uses GlobalWire and GlobalUnWire can be seen below:

/* * GlobalWire * globwire.c, jeffst, v1.00, 21-Sept-1987 * roberth, v1.05, 13-June-1988   The following program demonstrates the use of the GlobalWire * function. The GlobalWire function locks a block into low memory. * GlobalWire is called from WinMain in this sample application. * GlobalWire is often used when a block is going to be locked in * memory for a long time so there will be larger continuous free * spaces than if GlobalLock was used. Before allocation and after * GlobalWire’ing, GlobalCompact is called to show the affect of * locking the block in memory has on the largest continuous block   Microsoft Product Support Services * Windows Version 2.00 function demonstration application * Copyright (c) Microsoft 1987  / #include “windows.h” int sprintf; LPSTR FAR PASCAL lstrcpy (LPSTR, LPSTR); typedef struct { char smallstruct[20]; } SMALLSTRUCT; /* structure we’re going to allocate / / space for / typedef SMALLSTRUCT far lpSMALLPtr; /* pointer to SMALLSTRUCT structure / int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow ) HANDLE hInstance, hPrevInstance; LPSTR lpszCmdLine; int cmdShow; { HANDLE hMemBlock; / Handle to memory block / lpSMALLPtr ThisPtr; / Pointer to myStruct / char szBuff[80]; / buffer for output / DWORD ContigFreeBytes; / return value from GlobalCompact / / Allocate space for SMALLSTRUCT in global heap / hMemBlock = GlobalAlloc(GMEM_ZEROINIT | GMEM_MOVEABLE, (long)sizeof(SMALLSTRUCT)); / if memory allocated properly / if (hMemBlock != NULL) / GlobalWire the block into low memory / ThisPtr = (lpSMALLPtr)GlobalLock (hMemBlock); lstrcpy (ThisPtr->smallstruct, (LPSTR)“This is a test\000”); GlobalUnlock (hMemBlock); ThisPtr = (lpSMALLPtr)GlobalWire(hMemBlock); if (ThisPtr == NULL) MessageBox(NULL,(LPSTR)“GlobalWire Failure”, (LPSTR)&quot; “,MB_OK); else MessageBox(NULL,(LPSTR)”GlobalWire worked properly&quot;, (LPSTR)ThisPtr->smallstruct,MB_OK); / GlobalUnwire the block / GlobalUnWire(hMemBlock); / Free the block */ GlobalFree(hMemBlock); return 0; }

Additional reference words: 2.0 3.0 KBCategory: KBSubcategory: KrMmFixlockwire Copyright Microsoft Corporation 1993.