unsigned long NEAR PASCAL MyEnumKey(HKEY hKey, WORD wIndex, HANDLE *hBuf) { HANDLE hTemp; PSTR pBuf; WORD wBufSize = BLOCKLEN, wSize; unsigned long result = ERROR_OUTOFMEMORY; if(!(*hBuf=LocalAlloc(LMEM_MOVEABLE, wBufSize))) goto Error1; if(!(pBuf=LocalLock(*hBuf))) goto Error2; while((result=RegEnumKey(hKey, wIndex, pBuf, (DWORD)wBufSize)) ==ERROR_SUCCESS && (wSize=lstrlen(pBuf))>wBufSize-10) { LocalUnlock(*hBuf); wBufSize += BLOCKLEN; if(!(hTemp=LocalReAlloc(*hBuf, wBufSize, LMEM_MOVEABLE))) { result = ERROR_OUTOFMEMORY; goto Error2; } pBuf = LocalLock(*hBuf=hTemp); } LocalUnlock(*hBuf); if(result!=ERROR_SUCCESS || !wSize) goto Error2; goto Error1; Error2: LocalFree(*hBuf); *hBuf = NULL; Error1: return(result); }
unsigned long NEAR PASCAL MyQueryValue(HKEY hKey, PSTR pSubKey, HANDLE *hBuf) { HANDLE hTemp; PSTR pBuf; WORD wBufSize = BLOCKLEN; unsigned long result = ERROR_OUTOFMEMORY; LONG lSize; if(!(*hBuf=LocalAlloc(LMEM_MOVEABLE, wBufSize))) goto Error1; if(!(pBuf=LocalLock(*hBuf))) goto Error2; while((lSize=wBufSize, (result=RegQueryValue(hKey, pSubKey, pBuf, &lSize)) ==ERROR_SUCCESS) && (WORD)lSize>wBufSize-10) { LocalUnlock(*hBuf); wBufSize += BLOCKLEN; if(!(hTemp=LocalReAlloc(*hBuf, wBufSize, LMEM_MOVEABLE))) { result = ERROR_OUTOFMEMORY; goto Error2; } pBuf = LocalLock(*hBuf=hTemp); } LocalUnlock(*hBuf); if(result!=ERROR_SUCCESS || !lSize) goto Error2; goto Error1; Error2: LocalFree(*hBuf); *hBuf = NULL; Error1: return(result); }
// --------------------------------------------------------------------------- // HBITMAP __fastcall TForm1::SPI_LoadImage(String fileName) { /* 対応プラグインの検索 */ for (int i = 0; i < hSPI->Count; i++) { // プラグイン関数の取得 SPI_ISSUPPORTED spi_issupported = (SPI_ISSUPPORTED) GetProcAddress((HMODULE) hSPI->Items[i], SPIPROC_ISSUPPORTED); SPI_GETPICTURE spi_getpicture = (SPI_GETPICTURE) GetProcAddress((HMODULE) hSPI->Items[i], SPIPROC_GETPICTURE); if (spi_issupported == NULL || spi_getpicture == NULL) { continue; } // File内容をロードする HANDLE handle; // = NULL; if ((handle = CreateFile_Read(fileName.w_str())) == INVALID_HANDLE_VALUE) { return NULL; } DWORD filesize = GetFileSize(handle, NULL), readsize; LPSTR data = (LPSTR) Heap_Malloc(filesize); SetFilePointer(handle, 0, NULL, FILE_BEGIN); if (!ReadFile(handle, data, filesize, &readsize, NULL)) { CloseHandle(handle); } CloseHandle(handle); // ロードできる形式かどうかをチェックする if (spi_issupported(AnsiString(fileName).c_str(), (DWORD) data) == 0) { Heap_Free(data); continue; } // 画像を展開する HLOCAL info, bm; if (spi_getpicture(data, filesize, 1, &info, &bm, NULL, 0) != 0) { Heap_Free(data); } LPBITMAPINFO bmpinfo = (LPBITMAPINFO) LocalLock(info); // BITMAPINFO構造体 LPBYTE bmbits = (LPBYTE) LocalLock(bm); // 画像データ // 取得した情報からBITMAPハンドルを生成する HDC dc = GetDC(0); HBITMAP bitmap = CreateDIBitmap(dc, &bmpinfo->bmiHeader, CBM_INIT, bmbits, bmpinfo, DIB_RGB_COLORS); ReleaseDC(0, dc); // Free etc... LocalUnlock(info); LocalFree(info); LocalUnlock(bm); LocalFree(bm); Heap_Free(data); return bitmap; } return NULL; }
/* MDIWndProc */ LRESULT CALLBACK MDIWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HANDLE hInfo; PINFO pInfo; MSG msg; EventRecord macEvent; LONG thePoints = GetMessagePos(); PAINTSTRUCT ps; msg.hwnd = hwnd; msg.message = message; msg.wParam = wParam; msg.lParam = lParam; msg.time = GetMessageTime(); msg.pt.x = LOWORD(thePoints); msg.pt.y = HIWORD(thePoints); WinEventToMacEvent(&msg, &macEvent); switch (message) { case WM_CREATE: case WM_MDICREATE: break; case WM_DESTROY: hInfo = (HANDLE)GetWindowLong(hwnd, GWL_USERDATA); if (hInfo) { if ((pInfo = (PINFO)LocalLock(hInfo)) != NULL){ if (pInfo->gi) // close the graphic import component CloseComponent(pInfo->gi); // Destroy our port association DestroyPortAssociation((CGrafPort *)GetHWNDPort(pInfo->hwndChildWindow)); } LocalUnlock(hInfo); } break; // Draw our graphic case WM_PAINT: BeginPaint(hwnd, &ps); hInfo = (HANDLE)GetWindowLong(hwnd, GWL_USERDATA); if (hInfo) { if ((pInfo = (PINFO)LocalLock(hInfo)) != NULL) GraphicsImportDraw(pInfo->gi); LocalUnlock(hInfo); } EndPaint(hwnd, &ps); break; default: return DefMDIChildProc(hwnd, message, wParam, lParam); } return DefMDIChildProc(hwnd, message, wParam, lParam); }
static BOOL LGetEditCtrlMinMaxValue (HWND hwnd, HWND hwndCtl, DWORD FAR * lpdwMin, DWORD FAR * lpdwMax) { int id = GetDlgCtrlID(hwndCtl); INFOOFFSET infoIdx = GetSelectedStructure(hwnd); HLOCAL hmem = GetProp(hwnd, SZINFODEF); LPSTRUCTINFO lpinfo = LocalLock(hmem); switch (id) { case IDC_ROWS: *lpdwMin = infoMin[infoIdx].dwRows; *lpdwMax = lpinfo[infoIdx].dwRows; break; case IDC_ROWWIDTH: *lpdwMin = infoMin[infoIdx].nRowWidth; *lpdwMax = lpinfo[infoIdx].nRowWidth; break; case IDC_UNIQUEKEYS: *lpdwMin = infoMin[infoIdx].dwUniqueKeys; *lpdwMax = lpinfo[infoIdx].dwUniqueKeys; break; case IDC_KEYWIDTH: *lpdwMin = infoMin[infoIdx].nKeyWidth; *lpdwMax = lpinfo[infoIdx].nKeyWidth; break; case IDC_DATA: *lpdwMin = infoMin[infoIdx].fillFactors.nData; *lpdwMax = 100; break; case IDC_INDEX: *lpdwMin = infoMin[infoIdx].fillFactors.nIndex; *lpdwMax = 100; break; case IDC_LEAF: *lpdwMin = infoMin[infoIdx].fillFactors.nLeaf; *lpdwMax = 100; break; default: ASSERT(NULL); *lpdwMin = 0; *lpdwMax = 0; LocalUnlock(hmem); return FALSE; } LocalUnlock(hmem); return TRUE; }
void CEditView::ReadFromArchive(CArchive& ar, UINT nLen) // Read certain amount of text from the file, assume at least nLen // characters (not bytes) are in the file. { ASSERT_VALID(this); LPVOID hText = LocalAlloc(LMEM_MOVEABLE, (nLen+1)*sizeof(TCHAR)); if (hText == NULL) AfxThrowMemoryException(); LPTSTR lpszText = (LPTSTR)LocalLock(hText); ASSERT(lpszText != NULL); if (ar.Read(lpszText, nLen*sizeof(TCHAR)) != nLen*sizeof(TCHAR)) { LocalUnlock(hText); LocalFree(hText); AfxThrowArchiveException(CArchiveException::endOfFile); } // Replace the editing edit buffer with the newly loaded data lpszText[nLen] = '\0'; #ifndef _UNICODE if (afxData.bWin32s) { // set the text with SetWindowText, then free BOOL bResult = ::SetWindowText(m_hWnd, lpszText); LocalUnlock(hText); LocalFree(hText); // make sure that SetWindowText was successful if (!bResult || ::GetWindowTextLength(m_hWnd) < (int)nLen) AfxThrowMemoryException(); // remove old shadow buffer delete[] m_pShadowBuffer; m_pShadowBuffer = NULL; m_nShadowSize = 0; ASSERT_VALID(this); return; } #endif LocalUnlock(hText); HLOCAL hOldText = GetEditCtrl().GetHandle(); ASSERT(hOldText != NULL); LocalFree(hOldText); GetEditCtrl().SetHandle((HLOCAL)(UINT)(DWORD)hText); Invalidate(); ASSERT_VALID(this); }
/* * SizeHintBar - resize the hint bar */ WORD SizeHintBar( statwnd *wnd ) { HLOCAL hinfo; HintWndInfo *info; HFONT font; HFONT oldfont; HDC dc; SIZE sz; RECT area; HWND hint; hint = GetHintHwnd( wnd ); hinfo = GetProp( hint, HINT_PROP_ID ); info = LocalLock( hinfo ); dc = GetDC( hint ); font = GetMonoFont(); oldfont = SelectObject( dc, font ); GetTextExtentPoint( dc, "A", 1, &sz ); SelectObject( dc, oldfont ); ReleaseDC( hint, dc ); GetClientRect( info->parent, &area ); area.top = area.bottom - sz.cy - TOTAL_VERT; MoveWindow( hint, area.left, area.top, area.right - area.left, area.bottom - area.top, TRUE ); updateHintText( wnd, info->curmsg ); GetWindowRect( hint, &area ); LocalUnlock( hinfo ); return( (WORD)( area.bottom - area.top ) ); } /* SizeHintBar */
/* * getItemMsg - find the hint message for the specified menu item */ static msg_id getItemMsg( statwnd *wnd, ctl_id menuid ) { int i; HWND hint; HLOCAL hinfo; HintWndInfo *info; const MenuItemHint *hinttable; msg_id msgid; hint = GetHintHwnd( wnd ); hinfo = GetProp( hint, HINT_PROP_ID ); info = LocalLock( hinfo ); hinttable = info->hints; msgid = HINT_EMPTY; if( hinttable != NULL ) { for( i = 0; i < info->hint_num_items; i++ ) { if( hinttable[i].menuid == menuid ) { msgid = hinttable[i].msgid; break; } } } LocalUnlock( hinfo ); return( msgid ); } /* getItemMsg */
void near *lmem_realloc( /**********************/ void *mem, unsigned size ) { #ifdef PLAT_OS2 return( realloc( mem, (size_t) size ) ); #else HANDLE hld; void near *ptr; if( mem != NULL ) { hld = _wpi_getlocalhdl( mem ); if( hld ) { LocalUnlock( hld ); hld = LocalReAlloc( hld, size, LMEM_MOVEABLE ); if( hld ) { ptr = LocalLock( hld ); return( ptr ); } } } else { return( lmem_alloc( size ) ); } return( NULL ); #endif }
static void Adjust4FillFactors(HWND hwnd) /* Function: Adjusts the maximum values of limits that are affected by the changes in fill factors. Parameters: hwnd - Handle of dialog window Returns: None. */ { INFOOFFSET infoIdx = GetSelectedStructure(hwnd); STRUCTINFO info; HLOCAL hmem = GetProp(hwnd, SZINFODEF); LPSTRUCTINFO lpinfo = LocalLock(hmem); info.nIngresVersion= GetOIVers(); GetDialogInfo(hwnd, &info); /* ** BUG #112863 : in r3 the row width can be 256K and row can span page! */ if (info.nIngresVersion < OIVERS_30) { if (info.dwPageSize == 65536L) lpinfo[infoIdx].nRowWidth = 32767L; else lpinfo[infoIdx].nRowWidth = info.dwPageSize - GetPageOverHead(info.iPageType) - GetRowOverHead(info.iPageType); } LocalUnlock(hmem); }
static VOID HandleSetHandlePrintHex(HWND handle,DWORD Msg,WPARAM wParam,LPARAM lParam) { LPVOID pMem; HANDLE hNewBuffer; int ret; LocalFree((HLOCAL)SendMessage(handle, EM_GETHANDLE, 0, 0L)); if (UnicodeUsed) { hNewBuffer = LocalAlloc(LMEM_MOVEABLE | LMEM_ZEROINIT, 100); pMem = LocalLock(hNewBuffer); strcpyw_((wchar_t*)pMem,NewTextW); } else { hNewBuffer = LocalAlloc(LMEM_MOVEABLE | LMEM_ZEROINIT,50); pMem = LocalLock(hNewBuffer); strcpy_((char*)pMem,NewText); } LocalUnlock(pMem); hNewBuffer = LocalHandle(pMem); /* Updates the buffer and displays new buffer */ ret = SendMessage(handle, EM_SETHANDLE, (WPARAM)hNewBuffer, 0L); htoa(ret,&TextBuffer[8]); PrintTextXY(TextBuffer,ResultX,ResultY,16); }
void GHOST_SystemWin32::putClipboard(GHOST_TInt8 *buffer, bool selection) const { if (selection) {return; } // for copying the selection, used on X11 if (OpenClipboard(NULL)) { HLOCAL clipbuffer; wchar_t *data; if (buffer) { size_t len = count_utf_16_from_8(buffer); EmptyClipboard(); clipbuffer = LocalAlloc(LMEM_FIXED, sizeof(wchar_t) * len); data = (wchar_t *)GlobalLock(clipbuffer); conv_utf_8_to_16(buffer, data, len); LocalUnlock(clipbuffer); SetClipboardData(CF_UNICODETEXT, clipbuffer); } CloseClipboard(); } else { return; } }
BOOL CStatusBar::Create(int x, int y, int iWidth, int iHeight, DWORD dwStyle, int nParts) { BOOL bRet = FALSE; LPINT lpParts; RECT rcClient; int nWidth = 0; m_hwndStatus = CreateWindowEx(0, STATUSCLASSNAME, NULL, dwStyle, x, y, iWidth, iHeight, m_hParent, m_hMenu, m_hInst, NULL); if (!m_hwndStatus) { return bRet; } GetClientRect(m_hParent, &rcClient); //allocates the specified number of bytes from the heap m_hLoc = LocalAlloc(LHND, sizeof(int) * nParts); lpParts = (LPINT)LocalLock(m_hLoc); nWidth = (rcClient.right - rcClient.left) / nParts; for (int i = 0; i < nParts; i++) { lpParts[i] = nWidth; nWidth += nWidth; } SendMessage(m_hwndStatus, SB_SETPARTS, (WPARAM)nParts, (LPARAM)lpParts); LocalUnlock(m_hLoc); LocalFree(m_hLoc); bRet = TRUE; return bRet; }
void CStationDlg::OnClickedDecodeh(void) { CEdit *cetodo = (CEdit *) CWnd::GetDlgItem(IDC_TODO1); int i,j; cetodo->GetSel(i,j); // NT SPECIFIC HLOCAL h = cetodo->GetHandle(); LPCTSTR lpszText = (LPCTSTR)LocalLock(h); char res[1000]; strncpy(res,&(lpszText[i]),j-i); SetDlgItemText(IDC_DECDEC,res); unsigned short f; unsigned char *pf; unsigned int b1,b2; pf = (unsigned char *)&f; sscanf(res,"%x %x",&b1,&b2); pf[0] = b1; pf[1] = b2; CString sres; sres.Format("%04X = %d",f,f); SetDlgItemText(IDC_DECFLOAT,sres); LocalUnlock(h); // END OF NT SPECIFIC }
void CStationDlg::OnClickedDecodesel(void) { CEdit *cetodo = (CEdit *) CWnd::GetDlgItem(IDC_TODO1); int i,j; cetodo->GetSel(i,j); // NT SPECIFIC HLOCAL h = cetodo->GetHandle(); LPCTSTR lpszText = (LPCTSTR)LocalLock(h); char res[1000]; strncpy(res,&(lpszText[i]),j-i);res[j-i] = 0; CString sres = res; sres.Replace("\r\n",""); SetDlgItemText(IDC_DECDEC,sres); float f; unsigned char *pf; unsigned int b1,b2,b3,b4; pf = (unsigned char *)&f; sscanf(sres,"%x %x %x %x",&b1,&b2,&b3,&b4); pf[0] = b1; pf[1] = b2; pf[2] = b3; pf[3] = b4; sres.Format("%g",f); SetDlgItemText(IDC_DECFLOAT,sres); LocalUnlock(h); // END OF NT SPECIFIC }
void LocalFreePtr(void *ptr) { HLOCAL hlocal; hlocal = LocalHandle(ptr); LocalUnlock(hlocal); LocalFree(hlocal); return; }
void * LocalReAllocPtr(void * ptr, UINT flags, UINT size) { HLOCAL hlocal; hlocal = LocalHandle(ptr); LocalUnlock(hlocal); hlocal = LocalReAlloc(hlocal, size+1, flags); return (char *)LocalLock(hlocal); }
static BOOL OccupyStructureControl (HWND hwnd) /* Function: Fills the structure drop down box with the structure names. Parameters: hwnd - Handle to the dialog window. Returns: TRUE if successful. */ { int i = 0; BOOL bRetVal = TRUE; HWND hwndCtl = GetDlgItem (hwnd, IDC_STRUCTURE); HLOCAL hmem; LPSTRUCTINFO lpinfo; if (!IsWindow(hwndCtl)) { ASSERT(FALSE); return FALSE; } hmem = GetProp(hwnd, SZINFODEF); lpinfo = LocalLock(hmem); while (lpinfo[i].nStructName != -1) { char szStructName[50]; int nIdx; if (LoadString(hResource, lpinfo[i].nStructName, szStructName, sizeof(szStructName)) == 0) bRetVal = FALSE; nIdx = ComboBox_AddString(hwndCtl, szStructName); if (nIdx == CB_ERR) bRetVal = FALSE; else ComboBox_SetItemData(hwndCtl, nIdx, (LPARAM)i); if (GetOIVers() >= OIVERS_20) lpinfo[i].nIngresVersion = GetOIVers(); i++; } // Set the first string in the list as the default if (bRetVal) ComboBox_SetCurSel(hwndCtl, 0); LocalUnlock(hmem); return bRetVal; }
int NEAR PASCAL MyGetProfileInt(WORD wAppName, WORD wKey, int nDefault) { HANDLE hAppName, hKey; if(!(hAppName=MyLoadString(wAppName, NULL, LMEM_MOVEABLE))) goto Error1; if(!(hKey=MyLoadString(wKey, NULL, LMEM_MOVEABLE))) goto Error2; nDefault = GetProfileInt(LocalLock(hAppName), LocalLock(hKey), nDefault); LocalUnlock(hKey); LocalUnlock(hAppName); Error2: LocalFree(hKey); Error1: LocalFree(hAppName); return(nDefault); }
void get_printSetup_with_PRINTDLG(PRINTDLG *pd, char **o_devmode, char **o_device, char **o_driver, char **o_output) { char *newDriver, *newDevice, *newOutput; DEVMODE *pDevmode; DEVNAMES *pDevnames; pDevmode = LocalLock(pd->hDevMode); *o_devmode = PassString(pDevmode->dmDeviceName); LocalUnlock(pd->hDevMode); pDevnames = LocalLock(pd->hDevNames); newDriver = ((char*)pDevnames)+(pDevnames->wDriverOffset); newDevice = ((char*)pDevnames)+(pDevnames->wDeviceOffset); newOutput = ((char*)pDevnames)+(pDevnames->wOutputOffset); *o_driver = PassString(newDriver); *o_device = PassString(newDevice); *o_output = PassString(newOutput); LocalUnlock(pd->hDevNames); }
static HANDLE setupDevmode(int size, char *pData) { HANDLE hDevmode; DEVMODE *pDevmode; hDevmode = (HANDLE) LocalAlloc(LMEM_MOVEABLE, size); pDevmode = LocalLock(hDevmode); memcpy((char*)pDevmode, pData, size); LocalUnlock(hDevmode); return hDevmode; }
static void InitialiseEditControls (HWND hwnd) { INFOOFFSET infoIdx = GetSelectedStructure(hwnd); char szNumber[20]; HLOCAL hmem = GetProp(hwnd, SZINFODEF); LPSTRUCTINFO lpinfo = LocalLock(hmem); bUserChangeEdit = FALSE; bInitEdit = TRUE; my_dwtoa(infoMin[infoIdx].dwRows, szNumber, 10); Edit_Enable(GetDlgItem(hwnd, IDC_ROWS), FALSE); Edit_SetText (GetDlgItem(hwnd, IDC_ROWS), szNumber); Edit_Enable(GetDlgItem(hwnd, IDC_ROWS), TRUE); my_itoa(infoMin[infoIdx].nRowWidth, szNumber, 10); Edit_SetText (GetDlgItem(hwnd, IDC_ROWWIDTH), szNumber); my_dwtoa(infoMin[infoIdx].dwUniqueKeys, szNumber, 10); Edit_SetText (GetDlgItem(hwnd, IDC_UNIQUEKEYS), szNumber); my_itoa(infoMin[infoIdx].nKeyWidth, szNumber, 10); Edit_SetText (GetDlgItem(hwnd, IDC_KEYWIDTH), szNumber); if (lpinfo[infoIdx].fillFactors.nData != -1) my_itoa(lpinfo[infoIdx].fillFactors.nData, szNumber, 10); else my_itoa(infoMin[infoIdx].fillFactors.nData, szNumber, 10); Edit_SetText (GetDlgItem(hwnd, IDC_DATA), szNumber); if (lpinfo[infoIdx].fillFactors.nIndex != -1) my_itoa(lpinfo[infoIdx].fillFactors.nIndex, szNumber, 10); else my_itoa(infoMin[infoIdx].fillFactors.nIndex, szNumber, 10); Edit_SetText (GetDlgItem(hwnd, IDC_INDEX), szNumber); if (lpinfo[infoIdx].fillFactors.nLeaf != -1) my_itoa(lpinfo[infoIdx].fillFactors.nLeaf, szNumber, 10); else my_itoa(infoMin[infoIdx].fillFactors.nLeaf, szNumber, 10); Edit_SetText (GetDlgItem(hwnd, IDC_LEAF), szNumber); if (lpinfo[infoIdx].fillFactors.nData != -1) SaveFillFactors.FillFactors.nData = lpinfo[infoIdx].fillFactors.nData; if (lpinfo[infoIdx].fillFactors.nIndex != -1) SaveFillFactors.FillFactors.nIndex = lpinfo[infoIdx].fillFactors.nIndex; if (lpinfo[infoIdx].fillFactors.nLeaf != -1) SaveFillFactors.FillFactors.nLeaf = lpinfo[infoIdx].fillFactors.nLeaf; bInitEdit = FALSE; LimitNumericEditControls(hwnd); LocalUnlock(hmem); }
/*---------------------------------------------------------------------------*\ | UNLOCK WINDOW INFO | This routine unlocks the memory the caller has previously locked. \*---------------------------------------------------------------------------*/ BOOL FAR UnlockWindowInfo(HWND hWnd) { HANDLE hMem; if(hMem = (HANDLE)GetWindowLongPtr(hWnd,0)) if(!LocalUnlock(hMem)) return(TRUE); return(FALSE); }
void TAppDictionary::FreeTable(TAppDictionaryEntry *pTable) { HANDLE hMem = #ifdef STRICT LocalHandle((void NEAR*)FP_OFF(pTable)); #else LocalHandle(FP_OFF(pTable)); #endif if (LocalUnlock(hMem)) LocalFree(hMem); }
VOID NEAR PASCAL WriteProfileInt(WORD wAppName, WORD wKey, int nVal) { HANDLE hAppName, hKey; char buf[10]; if(!(hAppName=MyLoadString(wAppName, NULL, LMEM_MOVEABLE))) goto Error1; if(!(hKey=MyLoadString(wKey, NULL, LMEM_MOVEABLE))) goto Error2; wsprintf(buf, "%d", nVal); WriteProfileString(LocalLock(hAppName), LocalLock(hKey), buf); LocalUnlock(hKey); LocalUnlock(hAppName); Error2: LocalFree(hKey); Error1: LocalFree(hAppName); }
//--------------------------------------------------------------------------- tTJSBinaryStream * tTVPSusieArchivePlugin::CreateStream(std::wstring localname, unsigned long pos, unsigned long size) { HLOCAL memhandle = NULL; int errorcode = 0xff & GetFile(const_cast<LPSTR>(ttstr(localname).AsNarrowStdString().c_str()), pos, (LPSTR)(void*)&memhandle, 0x0100, (FARPROC)ProgressCallback, 0); if(errorcode || memhandle == NULL) { TVPThrowExceptionMessage(TVPSusiePluginError, ttstr(TJS_W("tTVPSusieArchivePlugin::GetFile failed, errorcode = ")) + ttstr((tjs_int)errorcode)); } tTVPMemoryStream *memstream = new tTVPMemoryStream; void *memblock = NULL; try { memblock = LocalLock(memhandle); if(memblock == NULL) { TVPThrowExceptionMessage(TVPSusiePluginError, ttstr(TJS_W("tTVPSusieArchivePlugin::GetFile failed : invalid memory block."))); } // write to on-memory stream memstream->WriteBuffer(memblock, size); memstream->SetPosition(0); } catch(...) { if(memblock) LocalUnlock(memhandle); LocalFree(memhandle); delete memstream; throw; } if(memblock) LocalUnlock(memhandle); LocalFree(memhandle); return memstream; }
void CEditView::UnlockBuffer() const { ASSERT_VALID(this); ASSERT(m_hWnd != NULL); #ifndef _UNICODE if (afxData.bWin32s) return; #endif HLOCAL hLocal = GetEditCtrl().GetHandle(); ASSERT(hLocal != NULL); LocalUnlock(hLocal); }
HWND DoCreateStatusBar(HWND hwndParent, int idStatus, HINSTANCE hinst, int cParts) { HWND hwndStatus; RECT rcClient; HLOCAL hloc; PINT paParts; int i, nWidth; // Ensure that the common control DLL is loaded. InitCommonControls(); // Create the status bar. hwndStatus = CreateWindowEx( 0, // no extended styles STATUSCLASSNAME, // name of status bar class (PCTSTR) NULL, // no text when first created WS_CHILD | WS_VISIBLE, // creates a visible child window 0, 0, 0, 0, // ignores size and position hwndParent, // handle to parent window (HMENU) idStatus, // child window identifier hinst, // handle to application instance NULL); // no window creation data // Get the coordinates of the parent window's client area. GetClientRect(hwndParent, &rcClient); // Allocate an array for holding the right edge coordinates. hloc = LocalAlloc(LHND, sizeof(int) * cParts); paParts = (PINT) LocalLock(hloc); // Calculate the right edge coordinate for each part, and // copy the coordinates to the array. nWidth = rcClient.right / cParts; int rightEdge = nWidth; for (i = 0; i < cParts; i++) { paParts[i] = rightEdge; rightEdge += nWidth; } // Tell the status bar to create the window parts. SendMessage(hwndStatus, SB_SETPARTS, (WPARAM) cParts, (LPARAM) paParts); // Free the array, and return. LocalUnlock(hloc); LocalFree(hloc); ::SetWindowTextW(hwndStatus, L"asasd"); return hwndStatus; }
void SetNewBuffer(HANDLE hNewBuffer, PSTR Title) { if (hNewBuffer) { char *p = LocalLock(hNewBuffer); SetWindowText(hEditWnd, p); LocalUnlock(hNewBuffer); } else SetWindowText(hEditWnd, ""); SetWindowText(hWnd, Title); bChanges = FALSE; }
//*********************************************************************** // // void GetResultStr() // // This handles WM_IME_COMPOSITION with GCS_RESULTSTR flag on. // //*********************************************************************** void GetResultStr( HWND hwnd ) { LONG bufLen; // Storage for length of result str. LPSTR lpResultStr; // Pointer to result string. HIMC hIMC; // Input context handle. HLOCAL hMem; // Memory handle. // // If fail to get input context handle then do nothing. // if ( !( hIMC = ImmGetContext( hwnd ) ) ) return; // // Determines how much memory space to store the result string. // Applications should call ImmGetCompositionString with // GCS_RESULTSTR flag on, buffer length zero, to get the bullfer // length. // if ( ( bufLen = ImmGetCompositionString( hIMC, GCS_RESULTSTR, (void *)NULL, (DWORD) 0 ) ) <= 0 ) goto exit2; // // Allocates memory with bufLen+1 bytes to store the result // string. Here we allocale on more byte to put null character. // if ( !( hMem = LocalAlloc( LPTR, (int)bufLen + 1 ) ) ) goto exit2; if ( !( lpResultStr = (LPSTR) LocalLock( hMem ) ) ) goto exit1; // // Reads in the result string. // ImmGetCompositionString( hIMC, GCS_RESULTSTR, lpResultStr, bufLen ); // // Displays the result string. // DisplayResultString( hwnd, lpResultStr ); LocalUnlock( hMem ); exit1: LocalFree( hMem ); exit2: ImmReleaseContext( hwnd, hIMC ); }