// WriteDIB - Writes a DIB to file // Returns - TRUE on success // szFile - Name of file to write to // hDIB - Handle of the DIB BOOL CClientCapture::WriteDIB( CString csFile) { BITMAPFILEHEADER hdr; LPBITMAPINFOHEADER lpbi; if (!hDIB) return FALSE; CFile file; if( !file.Open( csFile, CFile::modeWrite|CFile::modeCreate) ) return FALSE; lpbi = (LPBITMAPINFOHEADER)hDIB; int nColors = 1 << lpbi->biBitCount; if( nColors > 256 ) nColors = 0; // Fill in the fields of the file header hdr.bfType = ((WORD) ('M' << 8) | 'B'); // is always "BM" hdr.bfSize = GlobalSize (hDIB) + sizeof( hdr ); hdr.bfReserved1 = 0; hdr.bfReserved2 = 0; hdr.bfOffBits = (DWORD) (sizeof( hdr ) + lpbi->biSize + nColors * sizeof(RGBQUAD)); // Write the file header file.Write( &hdr, sizeof(hdr) ); // Write the DIB header and the bits file.Write( lpbi, GlobalSize(hDIB) ); return TRUE; }
void CSemanticStrView::PasteClipboard() { OpenClipboard(); HGLOBAL hMem = ::GetClipboardData(CF_UNICODETEXT ); if (!hMem) { CloseClipboard(); return; } wchar_t s [5000]; if ( GlobalSize(hMem) > 4999) { AfxMessageBox (" Text is too big!"); }; CopyMemory( s, hMem, GlobalSize(hMem)); s[GlobalSize(hMem)] = 0; CString Q = s; char cmd[5200]; strcpy (cmd, "$main.controls.mainEntry insert 0.0 \""); for (size_t i=0; i < Q.GetLength();i++) if (s[i] == '"') strcat (cmd, "\\\""); else { size_t l = strlen(cmd); cmd[l] = Q[i]; cmd[l+1] = 0; }; strcat (cmd, "\""); if (Tcl_Eval(theInterp,cmd)!=0) AfxMessageBox ("Cannot set value"); CloseClipboard(); }
/* ================ Sys_GetClipboardData ================ */ char *Sys_GetClipboardData( clipboard_t clip ) { char *data = NULL; char *cliptext; if ( OpenClipboard( NULL ) != 0 ) { HANDLE hClipboardData; if ( ( hClipboardData = GetClipboardData( CF_TEXT ) ) != 0 ) { if ( ( cliptext = GlobalLock( hClipboardData ) ) != 0 ) { data = Z_Malloc( GlobalSize( hClipboardData ) + 1 ); Q_strncpyz( data, cliptext, GlobalSize( hClipboardData ) ); GlobalUnlock( hClipboardData ); strtok( data, "\n\r\b" ); } } CloseClipboard(); } return data; }
void COleClipSource::DoUpperLowerCase(CClip &clip, bool upper) { IClipFormat *unicodeTextFormat = clip.m_Formats.FindFormatEx(CF_UNICODETEXT); if (unicodeTextFormat != NULL) { HGLOBAL data = unicodeTextFormat->Data(); wchar_t * stringData = (wchar_t *) GlobalLock(data); int size = (int) GlobalSize(data); CString cs(stringData); GlobalUnlock(data); //free the old text we are going to replace it below with an upper case version unicodeTextFormat->Free(); CString val; if (upper) { val = cs.MakeUpper(); } else { val = cs.MakeLower(); } long lLen = val.GetLength(); HGLOBAL hGlobal = NewGlobalP(val.GetBuffer(), ((lLen+1) * sizeof(wchar_t))); val.ReleaseBuffer(); unicodeTextFormat->Data(hGlobal); } IClipFormat *asciiTextFormat = clip.m_Formats.FindFormatEx(CF_TEXT); if (asciiTextFormat != NULL) { HGLOBAL data = asciiTextFormat->Data(); char * stringData = (char *) GlobalLock(data); int size = (int) GlobalSize(data); CStringA cs(stringData); GlobalUnlock(data); //free the old text we are going to replace it below with an upper case version asciiTextFormat->Free(); CString val; if (upper) { val = cs.MakeUpper(); } else { val = cs.MakeLower(); } long lLen = val.GetLength(); HGLOBAL hGlobal = NewGlobalP(val.GetBuffer(lLen), lLen + sizeof(char)); val.ReleaseBuffer(); asciiTextFormat->Data(hGlobal); } }
static void win_pr2_copy_check(gx_device_win_pr2 * wdev) { HGLOBAL hdevmode = wdev->win32_hdevmode; HGLOBAL hdevnames = wdev->win32_hdevnames; DWORD devmode_len = (hdevmode) ? GlobalSize(hdevmode) : 0; DWORD devnames_len = (hdevnames) ? GlobalSize(hdevnames) : 0; if (wdev->original_device == wdev) return; wdev->hdcprn = NULL; wdev->win32_hdevmode = NULL; wdev->win32_hdevnames = NULL; wdev->original_device = wdev; if (devmode_len) { wdev->win32_hdevmode = GlobalAlloc(0, devmode_len); if (wdev->win32_hdevmode) { memcpy(GlobalLock(wdev->win32_hdevmode), GlobalLock(hdevmode), devmode_len); GlobalUnlock(wdev->win32_hdevmode); GlobalUnlock(hdevmode); } } if (devnames_len) { wdev->win32_hdevnames = GlobalAlloc(0, devnames_len); if (wdev->win32_hdevnames) { memcpy(GlobalLock(wdev->win32_hdevnames), GlobalLock(hdevnames), devnames_len); GlobalUnlock(wdev->win32_hdevnames); GlobalUnlock(hdevnames); } } }
//see Q160957 and http://developer.netscape.com/docs/manuals/communicator/DDE/index.htm static void GetOpenBrowserUrlsForBrowser(const char *szBrowser, HWND hwndDlg, HWND hwndCombo) { int windowCount, i; DWORD *windowId; DWORD dwResult; ATOM hSzBrowser = GlobalAddAtomA(szBrowser); ATOM hSzTopic = GlobalAddAtomA("WWW_ListWindows"); ddeAcked = 0; if ( !SendMessageTimeout(HWND_BROADCAST, WM_DDE_INITIATE, (WPARAM)hwndDlg, MAKELPARAM(hSzBrowser, hSzTopic), SMTO_ABORTIFHUNG|SMTO_NORMAL, DDEMESSAGETIMEOUT, (PDWORD_PTR)&dwResult) || !ddeAcked) { GlobalDeleteAtom(hSzTopic); GlobalDeleteAtom(hSzBrowser); return; } HGLOBAL hData = DoDdeRequest("WWW_ListWindows", hwndDlg); if (hData == NULL) { GlobalDeleteAtom(hSzTopic); GlobalDeleteAtom(hSzBrowser); return; } int dataLength = GlobalSize(hData)-offsetof(DDEDATA, Value); DDEDATA *data = (DDEDATA*)GlobalLock(hData); windowCount = dataLength / sizeof(DWORD); windowId = (PDWORD)mir_alloc(sizeof(DWORD)*windowCount); memcpy(windowId, data->Value, windowCount*sizeof(DWORD)); GlobalUnlock(hData); FreeDdeRequestData(hData); PostMessage(hwndDde, WM_DDE_TERMINATE, (WPARAM)hwndDlg, 0); GlobalDeleteAtom(hSzTopic); hSzTopic = GlobalAddAtomA("WWW_GetWindowInfo"); ddeAcked = 0; if ( !SendMessageTimeout(HWND_BROADCAST, WM_DDE_INITIATE, (WPARAM)hwndDlg, MAKELPARAM(hSzBrowser, hSzTopic), SMTO_ABORTIFHUNG|SMTO_NORMAL, DDEMESSAGETIMEOUT, (PDWORD_PTR)&dwResult) || !ddeAcked) { GlobalDeleteAtom(hSzTopic); GlobalDeleteAtom(hSzBrowser); mir_free(windowId); return; } for (i=0;i<windowCount;i++) { if (windowId[i] == 0) break; { char str[16]; mir_snprintf(str, _countof(str), "%d", windowId[i]); hData = DoDdeRequest(str, hwndDlg); } if (hData != NULL) { dataLength = GlobalSize(hData)-offsetof(DDEDATA, Value); data = (DDEDATA*)GlobalLock(hData); AddBrowserPageToCombo((char*)data->Value, hwndCombo); GlobalUnlock(hData); FreeDdeRequestData(hData); } } PostMessage(hwndDde, WM_DDE_TERMINATE, (WPARAM)hwndDlg, 0); GlobalDeleteAtom(hSzTopic); GlobalDeleteAtom(hSzBrowser); mir_free(windowId); }
void TABLE::tPaste() { if(TABLE_ATTRIBUTES::AutoFill()) return; BOOL available = IsClipboardFormatAvailable(CF_TEXT); if(!available) return; DestroyAllEditControls(); OpenClipboard(hParentWnd); HGLOBAL hClipboard = GetClipboardData(CF_TEXT); if(!hClipboard) { CloseClipboard(); return; } HGLOBAL hCopy = GlobalAlloc(GHND, GlobalSize(hClipboard)); if(!hCopy) { CloseClipboard(); return; } char* copy = (char*)GlobalLock(hCopy); char* clip = (char*)GlobalLock(hClipboard); hmemcpy(copy, clip, GlobalSize(hClipboard)); GlobalUnlock(hClipboard); CloseClipboard(); RUNTIMEINFO* rtime = (RUNTIMEINFO*)AObjGetRuntimeInfo(theObject); ROW* row = rtime->GetRow(); long first = row->FirstSelection(); char* token = (char*)myStrtok((char huge*)copy); while(token) { row->AddRow(first, token, TABLE_ATTRIBUTES::NumColumns(), FALSE); token = (char*)myStrtok(NULL); first++; } GlobalUnlock(hCopy); GlobalFree(hCopy); row->DeleteSelectedRows(); PostObjectChanged(CHANGED_NUMROWS); }
void winclipreceive(void) { HGLOBAL rmem; wchar_t *rptr; int i, rlen; if(OpenClipboard(NULL)) { rmem = GetClipboardData(CF_UNICODETEXT); if (rmem && (rptr = GlobalLock(rmem))) { rlen = GlobalSize(rmem) / sizeof(wchar_t); for (i=0; i < rlen; i++) { if (rptr[i] == '\0') break; else if (rptr[i] == '\r' || rptr[i] == '\n') continue; else if (rptr[i] == '\b' || rptr[i] == '\t') continue; else if (rptr[i] != 27) gli_input_handle_key(rptr[i]); } GlobalUnlock(rmem); } CloseClipboard(); } }
STDMETHODIMP QOleDataObject::GetDataHere( FORMATETC *pformatetc, STGMEDIUM *pmedium ) { // is data is in our format? HRESULT hr = QueryGetData( pformatetc ); if ( hr != S_OK ) return hr; if ( pmedium->tymed != TYMED_HGLOBAL ) return DV_E_TYMED; if ( !pmedium->hGlobal ) return STG_E_MEDIUMFULL; HGLOBAL hGlobal = pmedium->hGlobal; uint size = GlobalSize( hGlobal ); int cf = pformatetc->cfFormat; QPtrList<QWindowsMime> all = QWindowsMime::all(); for ( QWindowsMime * c = all.first(); c ; c = all.next() ) { const char * mime = c->mimeFor( cf ); if ( mime && m_dragObj->provides( mime ) ) { QByteArray ba = m_dragObj->encodedData( mime ); if ( ba.size() > size ) return STG_E_MEDIUMFULL; memcpy ( GlobalLock ( hGlobal ), ba.data(), ba.size() ); GlobalUnlock ( hGlobal ); return S_OK; } } return E_UNEXPECTED; }
bool CModDoc::PasteEnvelope(INSTRUMENTINDEX nIns, EnvelopeType nEnv) //---------------------------------------------------------------------- { CMainFrame *pMainFrm = CMainFrame::GetMainFrame(); if (nIns < 1 || nIns > m_SndFile.m_nInstruments || !m_SndFile.Instruments[nIns] || !pMainFrm) return false; BeginWaitCursor(); if (!pMainFrm->OpenClipboard()) { EndWaitCursor(); return false; } HGLOBAL hCpy = ::GetClipboardData(CF_TEXT); LPCSTR p; bool result = false; if ((hCpy) && ((p = (LPSTR)GlobalLock(hCpy)) != nullptr)) { std::string data(p, p + GlobalSize(hCpy)); GlobalUnlock(hCpy); CloseClipboard(); result = StringToEnvelope(data, m_SndFile.Instruments[nIns]->GetEnvelope(nEnv), m_SndFile.GetModSpecifications()); } EndWaitCursor(); return result; }
BOOL CDownloadDlg::OnInitDialog() { CSkinDialog::OnInitDialog(); SkinMe( NULL, IDR_DOWNLOADSFRAME ); if ( OpenClipboard() ) { if ( HGLOBAL hData = GetClipboardData( CF_UNICODETEXT ) ) { size_t nData = GlobalSize( hData ); LPVOID pData = GlobalLock( hData ); LPTSTR pszData = m_sURL.GetBuffer( (int)( nData + 1 ) / 2 + 1 ); CopyMemory( pszData, pData, nData ); pszData[ ( nData + 1 ) / 2 ] = 0; m_sURL.ReleaseBuffer(); GlobalUnlock( hData ); } CloseClipboard(); } m_sURL.Trim( _T(" \t\r\n") ); CShareazaURL pURL; if ( !pURL.Parse( m_sURL, m_pURLs ) ) m_sURL.Empty(); UpdateData( FALSE ); OnChangeURL(); return TRUE; }
bool CMemFileAccessor::CopyFromClipBroad(UINT ClipFormat) { if(OpenClipboard(NULL)) { HGLOBAL hClip=NULL; if( hClip=GetClipboardData(ClipFormat) ) { char *pBuff = (char *)GlobalLock(hClip); if(pBuff) { SAFE_DELETE_ARRAY(m_Buffer); m_BufferSize=GlobalSize(hClip); m_DataPtr=0; m_WriteSize=0; m_Buffer=new char[m_BufferSize]; memcpy(m_Buffer,pBuff,m_BufferSize); GlobalUnlock(hClip); CloseClipboard(); return true; } } CloseClipboard(); } return false; }
/****************************************************************************** * BIGBLOCKFILE_MemInit * * Initialize a big block object supported by an ILockBytes on HGLOABL. */ static BOOL BIGBLOCKFILE_MemInit(LPBIGBLOCKFILE This, ILockBytes* plkbyt) { This->hfile = 0; This->hfilemap = 0; /* * Retrieve the handle to the byte array from the LockByte object. */ if (GetHGlobalFromILockBytes(plkbyt, &(This->hbytearray)) != S_OK) { FIXME("May not be an ILockBytes on HGLOBAL\n"); return FALSE; } This->pLkbyt = plkbyt; /* * Increment the reference count of the ILockByte object since * we're keeping a reference to it. */ ILockBytes_AddRef(This->pLkbyt); This->filesize.u.LowPart = GlobalSize(This->hbytearray); This->filesize.u.HighPart = 0; This->pbytearray = GlobalLock(This->hbytearray); TRACE("mem on %p len %u\n", This->pbytearray, This->filesize.u.LowPart); return TRUE; }
tdata_t _TIFFrealloc(tdata_t p, tsize_t s) { void *pvTmp; tsize_t old; if (p == NULL) return ((tdata_t)GlobalAlloc(GMEM_FIXED, s)); old = GlobalSize(p); if (old >= s) { if ((pvTmp = GlobalAlloc(GMEM_FIXED, s)) != NULL) { CopyMemory(pvTmp, p, s); GlobalFree(p); } } else { if ((pvTmp = GlobalAlloc(GMEM_FIXED, s)) != NULL) { CopyMemory(pvTmp, p, old); GlobalFree(p); } } return ((tdata_t)pvTmp); }
String SystemClipboard::getTextFromClipboard() { String result; if (OpenClipboard (0) != 0) { HANDLE bufH = GetClipboardData (CF_UNICODETEXT); if (bufH != 0) { const WCHAR* const data = (const WCHAR*) GlobalLock (bufH); if (data != nullptr) { result = String (data, (int) (GlobalSize (bufH) / sizeof (WCHAR))); GlobalUnlock (bufH); } } CloseClipboard(); } return result; }
HGLOBAL GlobalFreeP( HGLOBAL hglbMem ) { HGLOBAL hReturn; DWORD dwSize; // get size of block before freeing it dwSize = (DWORD) GlobalSize(hglbMem); if (dwSize > 0) { // size was obtained OK so free the block hReturn = GlobalFree(hglbMem); if (hReturn == NULL) { // memory was freed if (pAppData != NULL) { // update call count pAppData->dwFreeCalls ++; pAppData->dwApplicationBytes -= dwSize; } } else { // memory was not freed so don't change data } } else { // unable to read memory size } return hReturn; }
void CScreenManager::SendLocalClipboard() { if (!::OpenClipboard(NULL)) { return; } HGLOBAL hglb = GetClipboardData(CF_TEXT); if (!hglb) { ::CloseClipboard(); return; } int nPacketLen = (int)GlobalSize(hglb) + 1; LPBYTE lpData = new(std::nothrow) BYTE[nPacketLen]; if (!lpData) { return; } LPSTR lpstr = (LPSTR)GlobalLock(hglb); lpData[0] = TOKEN_CLIPBOARD_TEXT; memcpy(lpData + 1, lpstr, nPacketLen - 1); ::GlobalUnlock(hglb); ::CloseClipboard(); Send(lpData, nPacketLen); delete[] lpData; }
PLUGINFUNCTIONEND PLUGINFUNCTIONSHORT(Copy) { int size = 0; HANDLE source, dest; char *str; // Get the string if ((str = system_popstring()) == NULL) return; // Check for size option if (str[0] == '/') { size = (int) myatoi64(str+1); dest = (HANDLE) popint64(); } else dest = (HANDLE) myatoi64(str); source = (HANDLE) popint64(); // Ok, check the size if (size == 0) size = (int) GlobalSize(source); // and the destinantion if ((int) dest == 0) { dest = GlobalAlloc((GPTR), size); system_pushint((int) dest); } // COPY! copymem(dest, source, size); GlobalFree(str); }
HRESULT CSite::HrStreamToFile(LPSTREAM pStream, LPCTSTR fileName) { HRESULT hr = S_OK; HGLOBAL hMem = NULL; LPVOID memBuf = NULL; DWORD memSize = 0; CFile file; if (file.Open(fileName, CFile::modeCreate | CFile::modeReadWrite, NULL) == FALSE) return E_FAIL; hr = GetHGlobalFromStream(pStream, &hMem); ASSERT(SUCCEEDED(hr)); memSize = GlobalSize(hMem); VERIFY(memBuf = GlobalLock(hMem)); file.Write(memBuf, memSize); // Reference count of hMem not checked here // since we can't assume how many times the // Stream has locked it GlobalUnlock(hMem); file.Close(); return hr; }
size_t WSizeBuffer(LPSTR ptr) { HANDLE hand; hand = GlobalPtrHandle(ptr); return GlobalSize(hand); }
bool UClipBoard::getFromClipboard(TCHAR *buf) { if (OpenClipboard (0) != 0) { HANDLE bufH = GetClipboardData (CF_TEXT); if (bufH != 0) { const char* const data = (const char*) GlobalLock (bufH); if (data != 0) { ::memcpy(buf, data, (int) (GlobalSize (bufH) / sizeof(char))); GlobalUnlock (bufH); } } CloseClipboard(); } return false; }
// @return INFO::OK iff text has been assigned a pointer (which the // caller must free via sys_clipboard_free) to the clipboard text. static Status GetClipboardText(wchar_t*& text) { // NB: Windows NT/2000+ auto convert CF_UNICODETEXT <-> CF_TEXT. if(!IsClipboardFormatAvailable(CF_UNICODETEXT)) return INFO::CANNOT_HANDLE; HGLOBAL hMem = GetClipboardData(CF_UNICODETEXT); if(!hMem) WARN_RETURN(ERR::FAIL); const wchar_t* lockedText = (const wchar_t*)GlobalLock(hMem); if(!lockedText) WARN_RETURN(ERR::NO_MEM); const size_t size = GlobalSize(hMem); text = (wchar_t*)malloc(size); if(!text) WARN_RETURN(ERR::NO_MEM); wcscpy_s(text, size/sizeof(wchar_t), lockedText); (void)GlobalUnlock(hMem); return INFO::OK; }
STDMETHODIMP GetData (FORMATETC *pFormatEtc, STGMEDIUM *pMedium) { oleSetup(); BOOL b = OpenClipboard(gClipboardWND); if (!b) return E_FAIL; HANDLE hData = GetClipboardData(pFormatEtc->cfFormat); LPVOID src = GlobalLock(hData); if(src) { ULONG size = GlobalSize(hData); HANDLE hDest = GlobalAlloc(GHND, size); LPVOID dest = GlobalLock(hDest); memcpy(dest, src, size); GlobalUnlock(hDest); GlobalUnlock(hData); hData = hDest; } pMedium->tymed = (hData == 0) ? TYMED_NULL : TYMED_HGLOBAL; pMedium->hGlobal = (HGLOBAL)hData; pMedium->pUnkForRelease = NULL; return S_OK; }
// getClipboardText(buf, buflen) static int getClipboardText(LPWSTR buf, int buflen) { int filetype = -1; // CF_UNICODETEXT HANDLE data = GetClipboardData(CF_UNICODETEXT); if (data != NULL) { LPWSTR text = (LPWSTR) GlobalLock(data); if (text != NULL) { filetype = FILETYPE_TEXT; StringCchCopy(buf, buflen, text); GlobalUnlock(data); } } // CF_DIB data = GetClipboardData(CF_DIB); if (data != NULL) { LPVOID bytes = GlobalLock(data); if (bytes != NULL) { SIZE_T nbytes = GlobalSize(data); filetype = FILETYPE_BITMAP; StringCchCopy(buf, buflen, MESSAGE_BITMAP); GlobalUnlock(bytes); } } return filetype; }
static BOOL ClipboardWriteMemory(HANDLE hFile, DWORD dwFormat, DWORD dwOffset, PDWORD pdwLength) { HGLOBAL hData; LPVOID lpData; DWORD dwBytesWritten; hData = GetClipboardData(dwFormat); if (!hData) return FALSE; lpData = GlobalLock(hData); if (!lpData) return FALSE; *pdwLength = GlobalSize(hData); if (SetFilePointer(hFile, dwOffset, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER) { GlobalUnlock(hData); return FALSE; } if (!WriteFile(hFile, lpData, *pdwLength, &dwBytesWritten, NULL)) { GlobalUnlock(hData); return FALSE; } GlobalUnlock(hData); return TRUE; }
// exportClipFile(basepath) static void exportClipFile(LPCWSTR basepath) { // CF_UNICODETEXT HANDLE data = GetClipboardData(CF_UNICODETEXT); if (data != NULL) { LPWSTR text = (LPWSTR) GlobalLock(data); if (text != NULL) { WCHAR path[MAX_PATH]; StringCchPrintf(path, _countof(path), L"%s.txt", basepath); setClipboardOrigin(path); writeTextFile(path, text, wcslen(text)); GlobalUnlock(data); } } // CF_DIB data = GetClipboardData(CF_DIB); if (data != NULL) { LPVOID bytes = GlobalLock(data); if (bytes != NULL) { SIZE_T nbytes = GlobalSize(data); WCHAR path[MAX_PATH]; StringCchPrintf(path, _countof(path), L"%s.bmp", basepath); setClipboardOrigin(path); writeBMPFile(path, bytes, nbytes); GlobalUnlock(bytes); } } }
static HRESULT WINAPI bsc_OnStopBinding( IBindStatusCallback* iface, HRESULT hresult, LPCWSTR szError) { bsc_t *This = impl_from_IBindStatusCallback(iface); HRESULT hr = S_OK; TRACE("(%p)->(%08x %s)\n", This, hresult, debugstr_w(szError)); if(This->binding) { IBinding_Release(This->binding); This->binding = NULL; } if(This->obj && SUCCEEDED(hresult)) { HGLOBAL hglobal; hr = GetHGlobalFromStream(This->memstream, &hglobal); if(SUCCEEDED(hr)) { DWORD len = GlobalSize(hglobal); char *ptr = GlobalLock(hglobal); hr = This->onDataAvailable(This->obj, ptr, len); GlobalUnlock(hglobal); } } return hr; }
/****************************************************************************** * HGLOBAL_UserSize [OLE32.@] */ unsigned long __RPC_USER HGLOBAL_UserSize(unsigned long *pFlags, unsigned long StartingSize, HGLOBAL *phGlobal) { unsigned long size = StartingSize; TRACE("("); dump_user_flags(pFlags); TRACE(", %ld, %p\n", StartingSize, phGlobal); ALIGN_LENGTH(size, 3); size += sizeof(ULONG); if (LOWORD(*pFlags == MSHCTX_INPROC)) size += sizeof(HGLOBAL); else { size += sizeof(ULONG); if (*phGlobal) { SIZE_T ret; size += 3 * sizeof(ULONG); ret = GlobalSize(*phGlobal); size += (unsigned long)ret; } } return size; }
GXHANDLE GXDLLAPI gxGetClipboardData( GXUINT uFormat // clipboard format ) { #if defined(_WINDOWS) || defined(_WIN32) HANDLE handle = GetClipboardData((GXUINT)uFormat); if(handle) { LPVOID ptr = GlobalLock(handle); SIZE_T size = GlobalSize(handle); if(g_hClipboard) { gxGlobalFree(g_hClipboard); } g_hClipboard = gxGlobalAlloc(NULL, size); GXLPVOID pNative = gxGlobalLock(g_hClipboard); memcpy(pNative, ptr, size); gxGlobalUnlock(g_hClipboard); GlobalUnlock(handle); return (GXHANDLE)g_hClipboard; } return NULL; #endif // #if defined(_WINDOWS) || defined(_WIN32) }
BSTR GetUnicodeHTML(CComPtr<IHTMLDocument2> spDocument) { ATLASSERT(!!spDocument); BSTR str = 0; // retrieve IPersistStreamInit interface CComQIPtr<IPersistStreamInit> persistStream = spDocument; ATLASSERT(!!persistStream); // save stream IStream* stream; CreateStreamOnHGlobal(NULL, TRUE, &stream); persistStream->Save(stream, FALSE); // lock stream memory HGLOBAL handle; GetHGlobalFromStream(stream, &handle); size_t size = GlobalSize(handle); LPVOID ptr = GlobalLock(handle); if (size>=2 && ((TCHAR*)ptr)[0]==0xFEFF) // we have her UCS-2LE Unicode little-endian { // copy string as is ATLASSERT(size%2==0); str = ::SysAllocStringLen(NULL, (ULONG)size>>1); memcpy(str, ptr, size); str[size>>1] = 0; // add ending marker }