LPBYTE DownloadToMemory(IN LPCTSTR lpszURL, OUT PDWORD_PTR lpSize)
{
	LPBYTE lpszReturn = 0;
	*lpSize = 0;
	const HINTERNET hSession = InternetOpen(TEXT("GetGitHubRepositoryList"), INTERNET_OPEN_TYPE_PRECONFIG, 0, 0, INTERNET_FLAG_NO_COOKIES);
	if (hSession)
	{
		URL_COMPONENTS uc = { 0 };
		TCHAR HostName[MAX_PATH];
		TCHAR UrlPath[MAX_PATH];
		uc.dwStructSize = sizeof(uc);
		uc.lpszHostName = HostName;
		uc.lpszUrlPath = UrlPath;
		uc.dwHostNameLength = MAX_PATH;
		uc.dwUrlPathLength = MAX_PATH;
		InternetCrackUrl(lpszURL, 0, 0, &uc);
		const HINTERNET hConnection = InternetConnect(hSession, HostName, INTERNET_DEFAULT_HTTPS_PORT, 0, 0, INTERNET_SERVICE_HTTP, 0, 0);
		if (hConnection)
		{
			const HINTERNET hRequest = HttpOpenRequest(hConnection, TEXT("GET"), UrlPath, 0, 0, 0, INTERNET_FLAG_SECURE | INTERNET_FLAG_RELOAD, 0);
			if (hRequest)
			{
				HttpSendRequest(hRequest, 0, 0, 0, 0);
				lpszReturn = (LPBYTE)GlobalAlloc(GMEM_FIXED, 1);
				DWORD dwRead;
				static BYTE szBuf[1024 * 4];
				LPBYTE lpTmp;
				for (;;)
				{
					if (!InternetReadFile(hRequest, szBuf, (DWORD)sizeof(szBuf), &dwRead) || !dwRead) break;
					lpTmp = (LPBYTE)GlobalReAlloc(lpszReturn, (SIZE_T)(*lpSize + dwRead), GMEM_MOVEABLE);
					if (lpTmp == NULL) break;
					lpszReturn = lpTmp;
					CopyMemory(lpszReturn + *lpSize, szBuf, dwRead);
					*lpSize += dwRead;
				}
				InternetCloseHandle(hRequest);
			}
			InternetCloseHandle(hConnection);
		}
		InternetCloseHandle(hSession);
	}
	return lpszReturn;
}
Esempio n. 2
0
void SelPrinter(HWND hDlg){
  PRINTDLG pd;
  ZeroMemory(&pd,sizeof(PRINTDLG));
  pd.lStructSize = sizeof(PRINTDLG);
  pd.hwndOwner = hDlg;

  HGLOBAL hNewDevMode = NULL;
  HGLOBAL hNewDevNames = NULL;
  if(hDevMode != NULL && hDevNames != NULL){
    int size = GetSizeOfDevMode(hDevMode);
    hNewDevMode = GlobalAlloc(GHND,size);
    GlobalCpy(hNewDevMode,hDevMode,size);
    size = GetSizeOfDevNames(hDevNames);
    hNewDevNames = GlobalAlloc(GHND,size);
    GlobalCpy(hNewDevNames,hDevNames,size);
  }
  pd.hDevMode = hNewDevMode;
  pd.hDevNames = hNewDevNames;
  pd.Flags = PD_USEDEVMODECOPIESANDCOLLATE | PD_RETURNDC | 
             PD_NOPAGENUMS | PD_NOSELECTION | PD_HIDEPRINTTOFILE;
  pd.nCopies = GetCurrentPrinterCopies();
  pd.nFromPage = 1;
  pd.nToPage = 1;
  pd.nMinPage = 1;
  pd.nMaxPage = 1;

  if(PrintDlg(&pd)){
    if(hPrintDC != NULL){
      DeleteDC(hPrintDC);
    }
    hPrintDC = pd.hDC;

    int size = GetSizeOfDevMode(pd.hDevMode);
    if(hDevMode != NULL){
      GlobalReAlloc(hDevMode,size,0);
    }else{
      hDevMode = GlobalAlloc(GHND,size);
    }
    GlobalCpy(hDevMode,pd.hDevMode,size);
    
    size = GetSizeOfDevNames(pd.hDevNames);
    if(hDevNames != NULL){
      GlobalReAlloc(hDevNames,size,0);
    }else{
      hDevNames = GlobalAlloc(GHND,size);
    }
    GlobalCpy(hDevNames,pd.hDevNames,size);

  }
  SetCurrentDirectoryToExePath();

  if(pd.hDevMode != NULL){
    GlobalFree(pd.hDevMode);
  }

  if(pd.hDevMode != NULL){
    GlobalFree(pd.hDevMode);
  }
}
Esempio n. 3
0
void SetHandleSize (Handle handle, size_t newSize)
{
	Ptr p;
	HANDLE hMem;


	memError = noErr;

	if (handle)
	{
		p = *handle;

		if (p)
		{
			GlobalUnlockPtr (p);
			hMem = GlobalReAlloc (GlobalPtrHandle (p), newSize, GHND);	
			if (hMem)
				p = (Ptr)GlobalLock (hMem);
			else
				p = NULL;
		}
 
		if (p)

			*handle = p;
		else

			memError = memFullErr;
	}

	else

		memError = memWZErr;

}
Esempio n. 4
0
/******************************************************************************
 * This method is part of the ILockBytes interface.
 *
 * It will change the size of the byte array.
 *
 * See the documentation of ILockBytes for more info.
 */
static HRESULT WINAPI HGLOBALLockBytesImpl_SetSize(
      ILockBytes*     iface,
      ULARGE_INTEGER  libNewSize)   /* [in] */
{
  HGLOBALLockBytesImpl* const This=(HGLOBALLockBytesImpl*)iface;
  HGLOBAL supportHandle;

  /*
   * As documented.
   */
  if (libNewSize.u.HighPart != 0)
    return STG_E_INVALIDFUNCTION;

  if (This->byteArraySize.u.LowPart == libNewSize.u.LowPart)
    return S_OK;

  /*
   * Re allocate the HGlobal to fit the new size of the stream.
   */
  supportHandle = GlobalReAlloc(This->supportHandle, libNewSize.u.LowPart, 0);

  if (supportHandle == 0)
    return STG_E_MEDIUMFULL;

  This->supportHandle = supportHandle;
  This->byteArraySize.u.LowPart = libNewSize.u.LowPart;

  return S_OK;
}
Esempio n. 5
0
long	UPSF::xxxx_To_UClr(
	HGLOBAL&	hUniv,
	long&			univSize,
	long			natv,
	void*			natvPtr,
	long			natvLen)

	{
	univSize = sizeof(short)*3L;
	if(!(hUniv = GlobalReAlloc(hUniv, univSize, MEMFLAGS)))
		return AUPSF_MEMORYERROR;

	short*	univPtr = (short*)GlobalLock(hUniv);
	if(!univPtr)
		return AUPSF_MEMORYERROR;

  long	retValue;

	if(natv==AUPSF_NATV_RGBCOLOR)
		{
		if(natvLen != sizeof(COLORREF))
			retValue = AUPSF_SIZEERROR;
    else
			retValue = RGBColor_To_UClr(univPtr, *(COLORREF*)natvPtr);
    }
	else
		retValue = AUPSF_CANTCONVERT;

	GlobalUnlock(hUniv);
	return retValue;
	}
Esempio n. 6
0
static void add_message(const struct message *msg)
{
    if (!sequence) {
        sequence_size = 10;
        sequence =
            (struct message *) GlobalAlloc(GMEM_DISCARDABLE,
                                           sequence_size *
                                           sizeof(struct message));
    }
    if (sequence_cnt == sequence_size) {
        sequence_size *= 2;
        sequence =
            (struct message *) GlobalReAlloc((char NEAR *) sequence,
                                             sequence_size *
                                             sizeof(struct message)
                                             , GMEM_DISCARDABLE);
    }
    assert(sequence);

    sequence[sequence_cnt].message = msg->message;
    sequence[sequence_cnt].flags = msg->flags;
    sequence[sequence_cnt].wParam = msg->wParam;
    sequence[sequence_cnt].lParam = msg->lParam;
    sequence_cnt++;
}
Esempio n. 7
0
/*
 * MemReAlloc - allocate some memory
 */
void *MemReAlloc( void *ptr, unsigned size )
{
    void *x;
#ifndef __OS2_PM__
#if defined( DEBUGMEM )
    GLOBALHANDLE        h;

    h = GlobalHandle( FP_SEG( ptr ) );
    GlobalUnlock( h );
    x = GlobalLock( GlobalReAlloc( h, size, GMEM_ZEROINIT | GMEM_MOVEABLE ) );
#else
    x = realloc( ptr, size );
#endif
#else
    x = realloc( ptr, size );
#endif
#if defined( WANT_MSGS )
    if( x == NULL ) {
        MessageBox( HWND_DESKTOP, "AUUGH, Null Pointer", "Memory Allocation",
                    MB_OK | MB_ICONHAND | MB_SYSTEMMODAL );
    }
#endif
    return( x );

} /* MemReAlloc */
Esempio n. 8
0
long	UPSF::xxxx_To_UFon(
	HGLOBAL&	hUniv,
	long&			univSize,
	long			natv,
	void*			natvPtr,
	long			natvLen)

	{
	univSize = natvLen;
	if(!(hUniv = GlobalReAlloc(hUniv, univSize, MEMFLAGS)))
		return AUPSF_MEMORYERROR;

	long*	univPtr = (long*)GlobalLock(hUniv);
	if(!univPtr)
		return AUPSF_MEMORYERROR;

	long	retValue = AUPSF_NOERROR;

	if(natv==AUPSF_NATV_FONT)
		{
		// just store the font name--each platform will convert on import
		// the attributes will be stored separately
		hmemcpy(univPtr, natvPtr, natvLen);
		}
	else
		retValue = AUPSF_CANTCONVERT;

	GlobalUnlock(hUniv);
	return retValue;
	}
Esempio n. 9
0
long	UPSF::xxxx_To_URct(
	HGLOBAL&	hUniv,
	long&			univSize,
	long			natv,
	void*			natvPtr,
	long			natvLen)

	{
	univSize = sizeof(long)*4L;
	if(!(hUniv = GlobalReAlloc(hUniv, univSize, MEMFLAGS)))
		return AUPSF_MEMORYERROR;

	long*	univPtr = (long*)GlobalLock(hUniv);
	if(!univPtr)
		return AUPSF_MEMORYERROR;

  long	retValue;

	if(natv==AUPSF_NATV_RECT)
		{
		if(natvLen != sizeof(RECT))
			retValue = AUPSF_SIZEERROR;
    else
			retValue = Rect_To_URct(univPtr, *(RECT*)natvPtr);
    }
	else
		retValue = AUPSF_CANTCONVERT;

	GlobalUnlock(hUniv);
  return retValue;
	}
Esempio n. 10
0
/***
 * This method is part of the IStream interface.
 *
 * It will change the size of a stream.
 *
 * TODO: Switch from small blocks to big blocks and vice versa.
 *
 * See the documentation of IStream for more info.
 */
static HRESULT WINAPI HGLOBALStreamImpl_SetSize(
				     IStream*      iface,
				     ULARGE_INTEGER  libNewSize)   /* [in] */
{
  HGLOBALStreamImpl* const This=(HGLOBALStreamImpl*)iface;
  HGLOBAL supportHandle;

  TRACE("(%p, %d)\n", iface, libNewSize.u.LowPart);

  /*
   * HighPart is ignored as shown in tests
   */

  if (This->streamSize.u.LowPart == libNewSize.u.LowPart)
    return S_OK;

  /*
   * Re allocate the HGlobal to fit the new size of the stream.
   */
  supportHandle = GlobalReAlloc(This->supportHandle, libNewSize.u.LowPart, 0);

  if (supportHandle == 0)
    return E_OUTOFMEMORY;

  This->supportHandle = supportHandle;
  This->streamSize.u.LowPart = libNewSize.u.LowPart;

  return S_OK;
}
Esempio n. 11
0
UBOOL AfoDetectResize
    (LPAFODETECT_STR lpafoDetectStr)

{
    // If there is no more room, ...
    if (lpafoDetectStr->uLineStrCnt EQ lpafoDetectStr->uLineStrNxt)
    {
        HGLOBAL hGlbLineStr;

        // Unlock the global memory handle so we may resize it
        GlobalUnlock (lpafoDetectStr->hGlbLineStr);

        // Reallocate the AFOLINE_STR
        //   moving the old data to the new location, and
        //   freeing the old global memory
        hGlbLineStr =
          GlobalReAlloc (lpafoDetectStr->hGlbLineStr,
                          (lpafoDetectStr->uLineStrCnt + AFOLINESTR_INCR) * sizeof (AFOLINE_STR),
                          GMEM_MOVEABLE);
        // Check for error
        if (hGlbLineStr EQ NULL)
            return FALSE;

        // Save (possibly new) handle
        lpafoDetectStr->hGlbLineStr  = hGlbLineStr;
        lpafoDetectStr->lpafoLineStr = GlobalLock (hGlbLineStr);

        return TRUE;
    } else
        return TRUE;
} // End AfoDetectResize
Esempio n. 12
0
HANDLE AllocRoomForDIB(BITMAPINFOHEADER bi, HBITMAP hBitmap)
{
    DWORD               dwLen;
    HANDLE              hDIB;
    HDC                 hDC;
    LPBITMAPINFOHEADER  lpbi;
    HANDLE              hTemp;

    // Figure out the size needed to hold the BITMAPINFO structure
    // (which includes the BITMAPINFOHEADER and the color table).

    dwLen = bi.biSize + PaletteSize((LPSTR) &bi);
    hDIB  = GlobalAlloc(GHND,dwLen);

    // Check that DIB handle is valid

    if (!hDIB)
        return NULL;

    // Set up the BITMAPINFOHEADER in the newly allocated global memory,
    // then call GetDIBits() with lpBits = NULL to have it fill in the
    // biSizeImage field for us.

    lpbi  = (LPBITMAPINFOHEADER)GlobalLock(hDIB);
    *lpbi = bi;

    hDC   = GetDC(NULL);

    GetDIBits(hDC, hBitmap, 0, (UINT) bi.biHeight, NULL, (LPBITMAPINFO)lpbi,
            DIB_RGB_COLORS);
    ReleaseDC(NULL, hDC);

    // If the driver did not fill in the biSizeImage field,
    // fill it in -- NOTE: this is a bug in the driver!
    
    if (lpbi->biSizeImage == 0)
        lpbi->biSizeImage = WIDTHBYTES((DWORD)lpbi->biWidth *
                lpbi->biBitCount) * lpbi->biHeight;

    // Get the size of the memory block we need

    dwLen = lpbi->biSize + PaletteSize((LPSTR) &bi) + lpbi->biSizeImage;

    // Unlock the memory block

    GlobalUnlock(hDIB);

    // ReAlloc the buffer big enough to hold all the bits 

    if (hTemp = GlobalReAlloc(hDIB,dwLen,0))
        return hTemp;
    else
    {
        // Else free memory block and return failure

        GlobalFree(hDIB);
        return NULL;
    }
}
Esempio n. 13
0
//********************************************************************
Handle MyReAlloc(Handle hMem,
				uint32_t dwSize,
				uint32_t dwFlag)
{
	return CFIO_ReAlloc?
		CFIO_ReAlloc(hMem, dwSize, dwFlag):
		GlobalReAlloc(hMem, dwSize, dwFlag);
}
Esempio n. 14
0
static HGLOBAL gmem_realloc(HGLOBAL *hg, unsigned size)
{
 HGLOBAL hn;
 if (hn = *hg? GlobalReAlloc(*hg, size, loGMEM_FLAG):
               GlobalAlloc(loGMEM_FLAG, size)) *hg = hn;
/* else
   {
    UL_WARNING((LOGID, "%!L gmem_alloc(%u) FAILED", size));
   }*/
 return hn;
}
Esempio n. 15
0
BOOL My_GlobalReAlloc()
{
	HGLOBAL hMem=NULL;
	SIZE_T dwBytes=NULL;
	UINT uFlags=NULL;
	HGLOBAL returnVal_Real = NULL;
	HGLOBAL returnVal_Intercepted = NULL;

	DWORD error_Real = 0;
	DWORD error_Intercepted = 0;
	__try{
	disableInterception();
	returnVal_Real = GlobalReAlloc (hMem,dwBytes,uFlags);
	error_Real = GetLastError();
	enableInterception();
	returnVal_Intercepted = GlobalReAlloc (hMem,dwBytes,uFlags);
	error_Intercepted = GetLastError();
	}__except(puts("in filter"), 1){puts("exception caught");}
	return ((returnVal_Real == returnVal_Intercepted) && (error_Real == error_Intercepted));
}
Esempio n. 16
0
tdata_t
_TIFFrealloc(tdata_t p, tsize_t s)
{
	void* pvTmp;
	if ((pvTmp = GlobalReAlloc(p, s, 0)) == NULL) {
		if ((pvTmp = GlobalAlloc(GMEM_FIXED, s)) != NULL) {
			CopyMemory(pvTmp, p, GlobalSize(p));
			GlobalFree(p);
		}
	}
	return ((tdata_t)pvTmp);
}
Esempio n. 17
0
void CMenuSpawn::AddImageItem(const int idx, WORD cmd)
{
	if (iImageItem == 0)
		pImageItem = (ImageItem *) GlobalAlloc(GPTR, sizeof(ImageItem));
	else
		pImageItem = (ImageItem *) GlobalReAlloc((HGLOBAL) pImageItem, sizeof(ImageItem) * (iImageItem + 1), GMEM_MOVEABLE|GMEM_ZEROINIT);
	
	ASSERT(pImageItem);
	pImageItem[iImageItem].iCmd = (int) cmd;
	pImageItem[iImageItem].iImageIdx = idx;
	iImageItem ++;
}
Esempio n. 18
0
static HGLOBAL get_rtf_text(ME_TextEditor *editor, const CHARRANGE *lpchrg)
{
    EDITSTREAM es;
    ME_GlobalDestStruct gds;

    gds.hData = GlobalAlloc(GMEM_MOVEABLE, 0);
    gds.nLength = 0;
    es.dwCookie = (DWORD_PTR)&gds;
    es.pfnCallback = ME_AppendToHGLOBAL;
    ME_StreamOutRange(editor, SF_RTF, lpchrg->cpMin, lpchrg->cpMax, &es);
    GlobalReAlloc(gds.hData, gds.nLength+1, 0);
    return gds.hData;
}
Esempio n. 19
0
void* prim_globalReAlloc(HGLOBAL arg1,DWORD arg2,UINT arg3)
{ static struct {HsPtr res1;HsInt gc_failed;HsPtr gc_failstring;} gc_result;
  HGLOBAL res1;int gc_failed;
	       char* gc_failstring;
  do {res1 = GlobalReAlloc(arg1, arg2, arg3);
      if ((gc_failed = ( res1==NULL ))) {gc_failstring = ErrorWin("GlobalReAlloc") ;}
      else {gc_failed = 0;}
      gc_result.res1 = (HGLOBAL)(res1);
      gc_result.gc_failed = gc_failed;
      gc_result.gc_failstring = gc_failstring;
      
      return(&gc_result);} while(0);
}
Esempio n. 20
0
static HGLOBAL get_rtf_text(ME_TextEditor *editor, const ME_Cursor *start, int nChars)
{
    EDITSTREAM es;
    ME_GlobalDestStruct gds;

    gds.hData = GlobalAlloc(GMEM_MOVEABLE, 0);
    gds.nLength = 0;
    es.dwCookie = (DWORD_PTR)&gds;
    es.pfnCallback = ME_AppendToHGLOBAL;
    ME_StreamOutRange(editor, SF_RTF, start, nChars, &es);
    GlobalReAlloc(gds.hData, gds.nLength+1, 0);
    return gds.hData;
}
Esempio n. 21
0
void AddScriptCmdArgs(const TCHAR *arg)
{
  g_sdata.script_cmd_args = GlobalReAlloc(g_sdata.script_cmd_args,
    GlobalSize(g_sdata.script_cmd_args) + (lstrlen(arg) + 2/* quotes */ + 1 /* space */)*sizeof(TCHAR),
    0);

  TCHAR *args = (TCHAR *) GlobalLock(g_sdata.script_cmd_args);

  lstrcat(args, _T(" \""));
  lstrcat(args, arg);
  lstrcat(args, _T("\""));

  GlobalUnlock(g_sdata.script_cmd_args);
}
Esempio n. 22
0
void
text_copy_to_clipboard(TW *tw)
{
    int size, count;
    HGLOBAL hGMem;
    LPSTR cbuf, cp;
    TEXTMETRIC tm;
    UINT type;
    HDC hdc;
    int i;

    size = tw->ScreenSize.y * (tw->ScreenSize.x + 2) + 1;
    hGMem = GlobalAlloc(GHND | GMEM_SHARE, (DWORD)size);
    cbuf = cp = (LPSTR)GlobalLock(hGMem);
    if (cp == (LPSTR)NULL)
	return;
    
    for (i=0; i<tw->ScreenSize.y; i++) {
	count = tw->ScreenSize.x;
	memcpy(cp, tw->ScreenBuffer + tw->ScreenSize.x*i, count);
	/* remove trailing spaces */
	for (count=count-1; count>=0; count--) {
		if (cp[count]!=' ')
			break;
		cp[count] = '\0';
	}
	cp[++count] = '\r';
	cp[++count] = '\n';
	cp[++count] = '\0';
	cp += count;
    }
    size = strlen(cbuf) + 1;
    GlobalUnlock(hGMem);
    hGMem = GlobalReAlloc(hGMem, (DWORD)size, GHND | GMEM_SHARE);
    /* find out what type to put into clipboard */
    hdc = GetDC(tw->hwnd);
    SelectFont(hdc, tw->hfont);
    GetTextMetrics(hdc,(TEXTMETRIC FAR *)&tm);
    if (tm.tmCharSet == OEM_CHARSET)
	type = CF_OEMTEXT;
    else
	type = CF_TEXT;
    ReleaseDC(tw->hwnd, hdc);
    /* give buffer to clipboard */
    OpenClipboard(tw->hwnd);
    EmptyClipboard();
    SetClipboardData(type, hGMem);
    CloseClipboard();
}
Esempio n. 23
0
void _fastcall ReAllocHGlobal(ParamBlk *parm)
{
	HGLOBAL hMem;
	hMem = GlobalReAlloc((HGLOBAL)p1.ev_long,(SIZE_T)p2.ev_long,GMEM_MOVEABLE|GMEM_ZEROINIT);
	if (hMem)
	{
		REPLACEDEBUGALLOC(p1.ev_long,hMem,p2.ev_long);		
		RET_INTEGER(hMem);
	}
	else
	{
		SAVEWIN32ERROR(GlobalReAlloc,GetLastError());
		RAISEERROREX(0);
	}
}
Esempio n. 24
0
static HRESULT WINAPI NoStatStreamImpl_SetSize(
				     IStream*      iface,
				     ULARGE_INTEGER  libNewSize)   /* [in] */
{
  NoStatStreamImpl* const This=(NoStatStreamImpl*)iface;
  HGLOBAL supportHandle;
  if (libNewSize.u.HighPart != 0)
    return STG_E_INVALIDFUNCTION;
  if (This->streamSize.u.LowPart == libNewSize.u.LowPart)
    return S_OK;
  supportHandle = GlobalReAlloc(This->supportHandle, libNewSize.u.LowPart, 0);
  if (supportHandle == 0)
    return STG_E_MEDIUMFULL;
  This->supportHandle = supportHandle;
  This->streamSize.u.LowPart = libNewSize.u.LowPart;
  return S_OK;
}
Esempio n. 25
0
void
IT_GLOBALREALLOC (ENV *envp,LONGPROC f)		/* GlobalReAlloc */
{
    UINT uiFlags, uSel;
    HGLOBAL hGlobal;
    LPBYTE  lpSeg;
    WORD wSP=0,wBP=0;
    DWORD dwNewSize;

    uSel = GETWORD(SP+10) | 1;
    uiFlags = (UINT)GETWORD(SP+4);
    dwNewSize = GETDWORD(SP+6);


    if (dwNewSize != 0) {
#ifdef LATER
	dwNewSize = max(dwNewSize,32);
	dwNewSize = (dwNewSize + 31) & 0xffffffe0;
#endif
        
	lpSeg = GetPhysicalAddress(uSel);
	if (uSel == envp->reg.ss) {
	    wSP = (WORD)(SP - lpSeg);
	    wBP = (WORD)(BP - lpSeg);
	}
	uSel = TWIN_ReallocSelector(uSel,dwNewSize,uiFlags);
	hGlobal = GetSelectorHandle(uSel);
	if (uSel == envp->reg.ss) {
	    envp->reg.sp = (REGISTER)(GetPhysicalAddress(uSel) + wSP);
	    envp->reg.bp = (REGISTER)(GetPhysicalAddress(uSel) + wBP);
	}
	if (uiFlags & GMEM_MOVEABLE) {
	    GlobalUnlock(hGlobal);
	    uSel &= 0xfffe;
	}
    } else {
	/* check if we are discarding, size 0,... */
	hGlobal = GetSelectorHandle(uSel);
	(void) GlobalReAlloc(hGlobal,0,uiFlags);
    }

    envp->reg.sp += HANDLE_86 + UINT_86 + DWORD_86 + RET_86;
    envp->reg.ax = LOWORD(uSel);
    envp->reg.dx = 0;
}
Esempio n. 26
0
long	UPSF::xxxx_To_xxxx(
	HGLOBAL&	hUniv,
	long&			univSize,
	void*			natvPtr,
	long			natvLen)

	{
	univSize = natvLen;
	if((hUniv = GlobalReAlloc(hUniv, natvLen, MEMFLAGS))==NULL)
		return AUPSF_MEMORYERROR;

	void*	univPtr = GlobalLock(hUniv);
	if(!univPtr)
		return AUPSF_MEMORYERROR;

	hmemcpy(univPtr, natvPtr, natvLen);
	GlobalUnlock(hUniv);
	return AUPSF_NOERROR;
	}
Esempio n. 27
0
HGLOBAL
GlobalReAllocP(
    HGLOBAL hglbMem,
    DWORD   cbBytes,
    UINT    fuFlags
)
{
   HGLOBAL hReturn;
   DWORD   dwBeforeSize = 0;
   DWORD   dwAfterSize  = 0;

   // get size of block before re-alloc-ing it
   dwBeforeSize = (DWORD) GlobalSize(hglbMem);
   if (dwBeforeSize > 0)
   {
      // size was obtained OK so realloc the block
      hReturn = GlobalReAlloc(hglbMem, cbBytes, fuFlags);
      if (hReturn != NULL)
      {
         // memory was re alloc'd so get the new size
         dwAfterSize = (DWORD) GlobalSize(hReturn);
      }
      else
      {
         // memory was not re-alloced so set after size to 0
      }
      if (pAppData != NULL)
      {
         // update call count
         pAppData->dwReAllocCalls ++;
         pAppData->dwApplicationBytes -= dwBeforeSize;
         pAppData->dwApplicationBytes += dwAfterSize;
      }
   }
   else
   {
      // unable to read memory size nothing has changed
      // return original pointer
      hReturn = hglbMem;
   }
   return hReturn;
}
Esempio n. 28
0
static DWORD CALLBACK ME_AppendToHGLOBAL(DWORD_PTR dwCookie, LPBYTE lpBuff, LONG cb, LONG *pcb)
{
    ME_GlobalDestStruct *pData = (ME_GlobalDestStruct *)dwCookie;
    int nMaxSize;
    BYTE *pDest;

    nMaxSize = GlobalSize(pData->hData);
    if (pData->nLength+cb+1 >= cb) {
        /* round up to 2^17 */
        int nNewSize = (((nMaxSize+cb+1)|0x1FFFF)+1) & 0xFFFE0000;
        pData->hData = GlobalReAlloc(pData->hData, nNewSize, 0);
    }
    pDest = GlobalLock(pData->hData);
    memcpy(pDest + pData->nLength, lpBuff, cb);
    pData->nLength += cb;
    pDest[pData->nLength] = '\0';
    GlobalUnlock(pData->hData);
    *pcb = cb;

    return 0;
}
Esempio n. 29
0
CMenuSpawn::SpawnItem * CMenuSpawn::AddSpawnItem(const char * txt, const int cmd)
{
	if (iSpawnItem == 0)
		pSpawnItem = (SpawnItem **) GlobalAlloc(GPTR, sizeof(SpawnItem));
	else
		pSpawnItem = (SpawnItem **) GlobalReAlloc((HGLOBAL) pSpawnItem, sizeof(SpawnItem) * (iSpawnItem + 1), GMEM_MOVEABLE|GMEM_ZEROINIT);

	ASSERT(pSpawnItem)

	SpawnItem * p = new SpawnItem;
	ASSERT(p);
	pSpawnItem[iSpawnItem] = p;
	lstrcpy(p->cText, txt);
	p->iCmd = cmd;

	if (cmd >= 0) p->iImageIdx = FindImageItem(cmd);
	else p->iImageIdx = cmd;

	iSpawnItem ++;
	return p;
}
Esempio n. 30
0
bool My_GlobalReAlloc(HGLOBAL ret, DWORD error)
{
	HGLOBAL dwRet = 0;

	////
	dwRet = GlobalReAlloc(GlobalAlloc(GMEM_MOVEABLE, 2), 2, GMEM_MODIFY);

	if (dwRet != ret)
		goto FAILED;

	if (!checkErrorCode(error))
		goto FAILED;

	uninterceptedPrint("GlobalReAlloc PASSED!\n");

return TRUE;

FAILED:
	uninterceptedPrint("GlobalReAlloc FAILED!\n");
	return FALSE;
}