当前位置: 首页>>代码示例>>C++>>正文


C++ GlobalAlloc函数代码示例

本文整理汇总了C++中GlobalAlloc函数的典型用法代码示例。如果您正苦于以下问题:C++ GlobalAlloc函数的具体用法?C++ GlobalAlloc怎么用?C++ GlobalAlloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了GlobalAlloc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: CreateBMPFile

void CreateBMPFile(HWND hwnd, LPTSTR pszFile, PBITMAPINFO pbi, HBITMAP hBMP, HDC hDC)
{
	HANDLE hf;                 // file handle  
	BITMAPFILEHEADER hdr;       // bitmap file-header  
	PBITMAPINFOHEADER pbih;     // bitmap info-header  
	LPBYTE lpBits;              // memory pointer  
	DWORD dwTotal;              // total count of bytes  
	DWORD cb;                   // incremental count of bytes  
	BYTE *hp;                   // byte pointer  
	DWORD dwTmp;

	pbih = (PBITMAPINFOHEADER)pbi;
	lpBits = (LPBYTE)GlobalAlloc(GMEM_FIXED, pbih->biSizeImage);

	if (!lpBits)
		errhandler("GlobalAlloc", hwnd);

	// Retrieve the color table (RGBQUAD array) and the bits  
	// (array of palette indices) from the DIB.  
	if (!GetDIBits(hDC, hBMP, 0, (WORD)pbih->biHeight, lpBits, pbi,
		DIB_RGB_COLORS))
	{
		errhandler("GetDIBits", hwnd);
	}

	// Create the .BMP file.  
	hf = CreateFile(pszFile,
		GENERIC_READ | GENERIC_WRITE,
		(DWORD)0,
		NULL,
		CREATE_ALWAYS,
		FILE_ATTRIBUTE_NORMAL,
		(HANDLE)NULL);
	if (hf == INVALID_HANDLE_VALUE)
		errhandler("CreateFile", hwnd);
	hdr.bfType = 0x4d42;        // 0x42 = "B" 0x4d = "M"  
	// Compute the size of the entire file.  
	hdr.bfSize = (DWORD)(sizeof(BITMAPFILEHEADER) +
		pbih->biSize + pbih->biClrUsed
		* sizeof(RGBQUAD) + pbih->biSizeImage);
	hdr.bfReserved1 = 0;
	hdr.bfReserved2 = 0;

	// Compute the offset to the array of color indices.  
	hdr.bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER) +
		pbih->biSize + pbih->biClrUsed
		* sizeof(RGBQUAD);

	// Copy the BITMAPFILEHEADER into the .BMP file.  
	if (!WriteFile(hf, (LPVOID)&hdr, sizeof(BITMAPFILEHEADER),
		(LPDWORD)&dwTmp, NULL))
	{
		errhandler("WriteFile", hwnd);
	}

	// Copy the BITMAPINFOHEADER and RGBQUAD array into the file.  
	if (!WriteFile(hf, (LPVOID)pbih, sizeof(BITMAPINFOHEADER)
		+ pbih->biClrUsed * sizeof(RGBQUAD),
		(LPDWORD)&dwTmp, (NULL)))
		errhandler("WriteFile", hwnd);

	// Copy the array of color indices into the .BMP file.  
	dwTotal = cb = pbih->biSizeImage;
	hp = lpBits;
	if (!WriteFile(hf, (LPSTR)hp, (int)cb, (LPDWORD)&dwTmp, NULL))
		errhandler("WriteFile", hwnd);

	// Close the .BMP file.  
	if (!CloseHandle(hf))
		errhandler("CloseHandle", hwnd);

	// Free memory.  
	GlobalFree((HGLOBAL)lpBits);
}
开发者ID:jakwuh,项目名称:bsu,代码行数:74,代码来源:bitmap.cpp

示例2: watchGlobalAlloc

HGLOBAL watchGlobalAlloc(UINT Flags, UINT size)
{
    HGLOBAL block = GlobalAlloc(Flags, size);
    blocks[blocksnum++] = block;
    return block;
}
开发者ID:kichik,项目名称:nsis-1,代码行数:6,代码来源:plugin.c

示例3: UpdateData

BOOL CCalcFrameDlg::OnCommand(WPARAM wParam, LPARAM lParam)
{
	UpdateData(TRUE);

	switch ( LOWORD(wParam) )
	{
	case ID_32771:			//标准型
		{
			CMenu *pMenu = GetMenu()->GetSubMenu(0);
			if( pMenu != NULL )
			{
				pMenu->CheckMenuItem(ID_32771,MF_CHECKED);
				pMenu->CheckMenuItem(ID_32772,MF_UNCHECKED);
			}

			OnBnClickedBtC();
			if( m_enWindowStyle == en_Normal ) return TRUE;
			m_enWindowStyle = en_Normal;
			PostMessage(WM_SIZE);
		}
		break;
	case ID_32772:			//科学型
		{
			CMenu *pMenu = GetMenu()->GetSubMenu(0);
			if( pMenu != NULL )
			{
				pMenu->CheckMenuItem(ID_32772,MF_CHECKED);
				pMenu->CheckMenuItem(ID_32771,MF_UNCHECKED);
			}

			OnBnClickedBtC();
			if( m_enWindowStyle == en_Science ) return TRUE;
			m_enWindowStyle = en_Science;
			PostMessage(WM_SIZE);
		}
		break;
	case ID_32773:			//最前显示
		{
			m_bFront = !m_bFront;

			GetMenu()->GetSubMenu(0)->CheckMenuItem(ID_32773,m_bFront?MF_CHECKED:MF_UNCHECKED);

			SetWindowPos(m_bFront? &wndTopMost : &wndNoTopMost,0,0,0,0,SWP_NOSIZE | SWP_NOMOVE);
		}
		break;
	case ID_32775:
		{
			//打开剪切板
			if (OpenClipboard()==FALSE) return TRUE;
			if (EmptyClipboard()==FALSE) { CloseClipboard(); return TRUE; }

			//复制数据
			HANDLE hData=GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT,m_strOutPut.GetLength()+1);
			if (hData==NULL) 
			{
				CloseClipboard();
				return TRUE;
			}

			LPTSTR szMemName=(LPTSTR)GlobalLock(hData);
			lstrcpy(szMemName,m_strOutPut);
			SetClipboardData(CF_TEXT,hData);
			GlobalUnlock(hData);
			CloseClipboard();

			break;
		}
	case ID_32776:
		{
			//判断剪贴板的数据格式是否可以处理。
			if (!IsClipboardFormatAvailable(CF_TEXT)) return TRUE;

			//打开剪贴板。
			if (!OpenClipboard()) return TRUE;

			//获取UNICODE的数据。
			HGLOBAL hMem = GetClipboardData(CF_TEXT);
			if (hMem != NULL)
			{
				LPTSTR lpStr = (LPTSTR)GlobalLock(hMem);
				if (lpStr != NULL)
				{
					for (int i=0;i<strlen(lpStr);i++)
					{
						BYTE bTemp = lpStr[i]-'0';
						if(bTemp<0 || bTemp>9) 
						{
							AfxMessageBox(TEXT("黏贴的字符不符合标准!"),MB_ICONSTOP);
							return TRUE;
						}
					}
					m_strOutPut = lpStr;

					//释放锁内存。
					GlobalUnlock(hMem);
				}
			}

			//关闭剪贴板。
			CloseClipboard();
//.........这里部分代码省略.........
开发者ID:HuugY,项目名称:MFC_Project,代码行数:101,代码来源:CalcFrameDlg.cpp

示例4: HeapCreate

void *globalrealloc(void *oldp,size_t newsize)
{
#if 0
    void *p;

    // Initialize heap
    if (!hHeap)
    {   hHeap = HeapCreate(0,0x10000,0);
        if (!hHeap)
            os_error();
    }

    newsize = (newsize + 3) & ~3L;      // round up to dwords
    if (newsize == 0)
    {
        if (oldp && HeapFree(hHeap,0,oldp) == FALSE)
            os_error();
        p = NULL;
    }
    else if (!oldp)
    {
        p = newsize ? HeapAlloc(hHeap,0,newsize) : NULL;
    }
    else
        p = HeapReAlloc(hHeap,0,oldp,newsize);
#elif 1
    MEMORY_BASIC_INFORMATION query;
    void *p;
    BOOL bSuccess;

    if (!oldp)
        p = VirtualAlloc (NULL, newsize, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
    else
    {
        VirtualQuery (oldp, &query, sizeof(query));
        if (!newsize)
        {
            p = NULL;
            goto L1;
        }
        else
        {   newsize = (newsize + 0xFFFF) & ~0xFFFFL;

            if (query.RegionSize >= newsize)
                p = oldp;
            else
            {   p = VirtualAlloc(NULL,newsize,MEM_COMMIT | MEM_RESERVE,PAGE_READWRITE);
                if (p)
                    memcpy(p,oldp,query.RegionSize);
            L1:
                bSuccess = VirtualFree(oldp,query.RegionSize,MEM_DECOMMIT);
                if (bSuccess)
                    bSuccess = VirtualFree(oldp,0,MEM_RELEASE);
                if (!bSuccess)
                    os_error();
            }
        }
    }
#else
    void *p;

    if (!oldp)
        p = (void *)GlobalAlloc (0, newsize);
    else if (!newsize)
    {   GlobalFree(oldp);
        p = NULL;
    }
    else
        p = (void *)GlobalReAlloc(oldp,newsize,0);
#endif
    dbg_printf("globalrealloc(oldp = %p, size = x%x) = %p\n",oldp,newsize,p);
    return p;
}
开发者ID:Abscissa,项目名称:dmd,代码行数:73,代码来源:os.c

示例5: marshal_WdtpInterfacePointer

static void marshal_WdtpInterfacePointer(DWORD umcb_ctx, DWORD ctx)
{
    USER_MARSHAL_CB umcb;
    MIDL_STUB_MESSAGE stub_msg;
    RPC_MESSAGE rpc_msg;
    unsigned char *buffer, *buffer_end;
    ULONG size;
    IUnknown *unk;
    IUnknown *unk2;
    unsigned char *wireip;
    HGLOBAL h = GlobalAlloc(GMEM_MOVEABLE, 0);
    IStream *stm;
    void *marshal_data;
    LARGE_INTEGER zero;
    ULARGE_INTEGER pos;
    DWORD marshal_size;

    /* shows that the WdtpInterfacePointer functions don't marshal anything for
     * NULL pointers, so code using these functions must handle that case
     * itself */

    unk = NULL;
    init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, umcb_ctx);
    size = WdtpInterfacePointer_UserSize(&umcb.Flags, ctx, 0, unk, &IID_IUnknown);
    ok(size == 0, "size should be 0 bytes, not %d\n", size);
    buffer = HeapAlloc(GetProcessHeap(), 0, size);
    buffer_end = WdtpInterfacePointer_UserMarshal(&umcb.Flags, ctx, buffer, unk, &IID_IUnknown);
    wireip = buffer;
    HeapFree(GetProcessHeap(), 0, buffer);

    /* Now for a non-NULL pointer. The marshalled data are two size DWORDS and then
       the result of CoMarshalInterface called with the LOWORD of the ctx */

    unk = &Test_Unknown;

    CreateStreamOnHGlobal(h, TRUE, &stm);
    CoMarshalInterface(stm, &IID_IUnknown, unk, LOWORD(ctx), NULL, MSHLFLAGS_NORMAL);
    zero.QuadPart = 0;
    IStream_Seek(stm, zero, STREAM_SEEK_CUR, &pos);
    marshal_size = pos.u.LowPart;
    marshal_data = GlobalLock(h);
    trace("marshal_size %x\n", marshal_size);

    init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, umcb_ctx);
    size = WdtpInterfacePointer_UserSize(&umcb.Flags, ctx, 0, unk, &IID_IUnknown);
    ok(size >= marshal_size + 2 * sizeof(DWORD), "marshal size %x got %x\n", marshal_size, size);
    trace("WdtpInterfacePointer_UserSize returned %x\n", size);
    buffer = HeapAlloc(GetProcessHeap(), 0, size);
    init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, umcb_ctx);
    buffer_end = WdtpInterfacePointer_UserMarshal(&umcb.Flags, ctx, buffer, unk, &IID_IUnknown);
    wireip = buffer;

    ok(buffer_end == buffer + marshal_size + 2 * sizeof(DWORD), "buffer_end %p buffer %p\n", buffer_end, buffer);

    ok(*(DWORD *)wireip == marshal_size, "wireip + 0x0 should be %x instead of %x\n", marshal_size, *(DWORD *)wireip);
    wireip += sizeof(DWORD);
    ok(*(DWORD *)wireip == marshal_size, "wireip + 0x4 should be %x instead of %x\n", marshal_size, *(DWORD *)wireip);
    wireip += sizeof(DWORD);

    ok(!memcmp(marshal_data, wireip, marshal_size), "buffer mismatch\n");
    GlobalUnlock(h);
    zero.QuadPart = 0;
    IStream_Seek(stm, zero, STREAM_SEEK_SET, NULL);
    CoReleaseMarshalData(stm);
    IStream_Release(stm);

    unk2 = NULL;
    init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, umcb_ctx);
    WdtpInterfacePointer_UserUnmarshal(&umcb.Flags, buffer, &unk2, &IID_IUnknown);
    ok(unk2 != NULL, "IUnknown object didn't unmarshal properly\n");
    HeapFree(GetProcessHeap(), 0, buffer);
    init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, MSHCTX_INPROC);
    WdtpInterfacePointer_UserFree(unk2);
}
开发者ID:pstrealer,项目名称:wine,代码行数:74,代码来源:usrmarshal.c

示例6: CommandLineToArgvA

	PCHAR* CommandLineToArgvA(PCHAR CmdLine, int* _argc)
	{
		PCHAR* argv;
		PCHAR  _argv;
		ULONG   len;
		ULONG   argc;
		CHAR   a;
		ULONG   i, j;

		BOOLEAN  in_QM;
		BOOLEAN  in_TEXT;
		BOOLEAN  in_SPACE;

		len = strlen(CmdLine);
		i = ((len + 2) / 2)*sizeof(PVOID)+sizeof(PVOID);

		argv = (PCHAR*)GlobalAlloc(GMEM_FIXED,
			i + (len + 2)*sizeof(CHAR));

		if (!argv)
			return 0;

		_argv = (PCHAR)(((PUCHAR)argv) + i);

		argc = 0;
		argv[argc] = _argv;
		in_QM = FALSE;
		in_TEXT = FALSE;
		in_SPACE = TRUE;
		i = 0;
		j = 0;

		while (a = CmdLine[i]) {
			if (in_QM) {
				if (a == '\"') {
					in_QM = FALSE;
				}
				else {
					_argv[j] = a;
					j++;
				}
			}
			else {
				switch (a) {
				case '\"':
					in_QM = TRUE;
					in_TEXT = TRUE;
					if (in_SPACE) {
						argv[argc] = _argv + j;
						argc++;
					}
					in_SPACE = FALSE;
					break;
				case ' ':
				case '\t':
				case '\n':
				case '\r':
					if (in_TEXT) {
						_argv[j] = '\0';
						j++;
					}
					in_TEXT = FALSE;
					in_SPACE = TRUE;
					break;
				default:
					in_TEXT = TRUE;
					if (in_SPACE) {
						argv[argc] = _argv + j;
						argc++;
					}
					_argv[j] = a;
					j++;
					in_SPACE = FALSE;
					break;
				}
			}
			i++;
		}
		_argv[j] = '\0';
		argv[argc] = NULL;

		(*_argc) = argc;
		return argv;
	}
开发者ID:Shad0wShayd3,项目名称:ElDorito,代码行数:84,代码来源:CommandMap.cpp

示例7: TT_GetUser

void COnlineUsersDlg::MenuCommand(UINT uCmd)
{
    int nUserID =  0;
    int count = m_wndUsers.GetItemCount();
    for(int i=0;i<count;i++)
    {
        if(m_wndUsers.GetItemState(i, LVIS_SELECTED) == LVIS_SELECTED)
            nUserID = m_wndUsers.GetItemData(i);
    }

    User user = {0};
    TT_GetUser(ttInst, nUserID, &user);
    Channel chan = {0};
    TT_GetChannel(ttInst, user.nChannelID, &chan);

    switch(uCmd)
    {
    case ID_POPUP_KICKANDBAN :
        TT_DoBanUser(ttInst, nUserID, 0);
        TT_DoKickUser(ttInst, nUserID, 0);
        break;
    case ID_POPUP_KICK :
        TT_DoKickUser(ttInst, nUserID, user.nChannelID);
        break;
    case ID_POPUP_OP :
        TT_DoChannelOpEx(ttInst, nUserID, user.nChannelID, chan.szOpPassword, 
                         !TT_IsChannelOperator(ttInst, nUserID, user.nChannelID));
        break;
    case ID_POPUP_COPYUSERINFORMATION :
    {
        User user;
        if(TT_GetUser(ttInst, nUserID, &user))
        {
            CString szText;
            CString szUserID;
            szUserID.Format(_T("%d"), user.nUserID);
            TTCHAR szChannel[TT_STRLEN] = _T("");
            TT_GetChannelPath(ttInst, user.nChannelID, szChannel);
            szText = szUserID;
            szText += _T("\t");
            szText += user.szNickname;
            szText += _T("\t");
            szText += user.szStatusMsg;
            szText += _T("\t");
            szText += user.szUsername;
            szText += _T("\t");
            szText += szChannel;
            szText += _T("\t");
            szText += user.szIPAddress;
            szText += _T("\t");
            szText += GetVersion(user);

            OpenClipboard();
            EmptyClipboard();
            HGLOBAL hglbCopy;
            hglbCopy = GlobalAlloc(GMEM_MOVEABLE,
                                   (szText.GetLength() + 1) * sizeof(TCHAR));
            if(hglbCopy)
            {
                LPVOID szStr = GlobalLock(hglbCopy);
                memcpy(szStr, szText.GetBuffer(), (szText.GetLength() + 1) * sizeof(TCHAR));
                GlobalUnlock(hglbCopy);
#if defined(UNICODE) || defined(_UNICODE)
                SetClipboardData(CF_UNICODETEXT, hglbCopy);
#else
                SetClipboardData(CF_TEXT, hglbCopy);
#endif
            }
            CloseClipboard();
        }
    }
    }
}
开发者ID:CowPanda,项目名称:TeamTalk5,代码行数:73,代码来源:OnlineUsersDlg.cpp

示例8: RegisterClipboardFormat

void ClipboardData::ToClipboard()
{
  //  do we have a name to restore??
  UINT format = uFormat;
  if ( dataName != NULL)
  {
    UINT u = RegisterClipboardFormat( dataName);
    if (u > 0)
    {
      //  the format has changed it seems.
      format = u;
    }
  }

  switch (format)
  {
  case CF_HDROP:
    {
      ClipboardDropData* cdd = static_cast<ClipboardDropData*>(data);

      // get the size of the clipboard.
      size_t size = cdd->GetDropfilesSize();
      if (size > 0)
      {
        // make some room for this DROPFILES item.
        HGLOBAL hGlobal = GlobalAlloc(GMEM_ZEROINIT | GMEM_MOVEABLE | GMEM_DDESHARE, size);

        // lock it so we can now use it.
        DROPFILES *df = (DROPFILES*)GlobalLock(hGlobal);
        
        // populate the data if we can.
        if (cdd->PopulateDropFiles(df, size))
        {
          // release the lock
          GlobalUnlock(hGlobal);

          // set the data in the clipboard.
          SetClipboardData(CF_HDROP, hGlobal);
        }
        else
        {
          // release the lock
          GlobalUnlock(hGlobal);

          // free the memory
          GlobalFree(hGlobal);
        }
      }
    }   
    break;

  case CF_ENHMETAFILE:
    SetClipboardData(CF_ENHMETAFILE, CopyEnhMetaFile((HENHMETAFILE)data, NULL));
    break;

  case CF_BITMAP:
    SetClipboardData(CF_BITMAP, CopyBitmap( (HBITMAP)data ));
    break;

  default:
    if (dataSize > 0)
    {
      //  get some data
      HGLOBAL hGlobal = GlobalAlloc(GMEM_ZEROINIT | GMEM_MOVEABLE | GMEM_DDESHARE, dataSize);
      void* pMem = GlobalLock(hGlobal);
      memcpy(pMem, data, dataSize);
      GlobalUnlock(hGlobal);

      // we can no save the data.
      SetClipboardData(format, hGlobal);
    }
    else
    {
      //  there is no data to set...
      SetClipboardData(format, 0);
    }
    break;
  }
}
开发者ID:FFMG,项目名称:myoddweb.piger,代码行数:79,代码来源:ClipboardData.cpp

示例9: _TIFFmalloc

tdata_t
_TIFFmalloc(tsize_t s)
{
    return ((tdata_t)GlobalAlloc(GMEM_FIXED, s));
}
开发者ID:CyberIntelMafia,项目名称:clamav-devel,代码行数:5,代码来源:tif_win32.c

示例10: DoGetRepStuff

void DoGetRepStuff(HWND hwnd, LPINSERTITEM pfr)
{                 
    HD_ITEM hi;
    int ret;
    HD_ITEM FAR* pitem;
    HGLOBAL hglb;
    int iAlloc;
    
    
    hi.mask = pfr->mask;
    hi.cxy = pfr->cxy;
    if (pfr->Nullpitem)
        pitem = NULL;
    else
        pitem = &hi;
            
    hi.cchTextMax = pfr->cchTextMax;
//  hi.cchTextMax = MAX_PSZTEXT;
    hi.fmt = pfr->fmt;
    hi.lParam = pfr->lParam;
    
    
    if (hi.cchTextMax == 0)
        iAlloc = MAX_PSZTEXT;
    else 
        iAlloc = hi.cchTextMax;
            
    if (pfr->NullpszText) 
        hi.pszText = NULL;              // can this be done ??
    else {
        hglb = GlobalAlloc(GPTR, iAlloc);
        hi.pszText = (LPSTR) GlobalLock(hglb);
//      _fstrcpy(hi.pszText, pfr->pszText);
    } 
    
    if (pfr->NullHwd) 
        ret = Header_GetItem(NULL, pfr->index, pitem);
    else
        ret = Header_GetItem(pfr->hwnd, pfr->index, pitem);

    wsprintf(szDbgMsg, "%d = Header_GetItem(index = %d,  \n\
    mask = %x )", ret, pfr->index, hi.mask);
    MyDebugMsg(DM_TRACE, "%s", (LPCSTR) szDbgMsg);
    SetDlgItemInt(hwnd, IDC_INSERTRET, ret, TRUE) ;
    
    if (ret) {
        SetDlgItemInt(hwnd, IDC_INSERTCXY, hi.cxy, TRUE);  
        SetDlgItemInt(hwnd, IDC_INSERTCCHTEXTMAX, hi.cchTextMax, TRUE);
        wsprintf(szTemp, szLongFilter, hi.lParam);
        SetDlgItemText(hwnd, IDC_INSERTLPARAM, szTemp);
        SetDlgItemText(hwnd, IDC_INSERTTEXT, hi.pszText);
        wsprintf(szTemp, "%04hx", hi.mask);
        SetDlgItemText(hwnd, IDC_INSERTMASK, szTemp);
        CheckDlgButton(hwnd, IDC_INSERTHDRIGHT, hi.fmt & HDF_RIGHT);
        CheckDlgButton(hwnd, IDC_INSERTHDLEFT, hi.fmt & HDF_LEFT);
        CheckDlgButton(hwnd, IDC_INSERTHDCENTER, hi.fmt & HDF_CENTER);
        CheckDlgButton(hwnd, IDC_INSERTHDJUSTIFYMASK, hi.fmt & HDF_JUSTIFYMASK);
        CheckDlgButton(hwnd, IDC_INSERTHDOWNERDRAW, hi.fmt & HDF_OWNERDRAW);
        CheckDlgButton(hwnd, IDC_INSERTHDSTRING, hi.fmt & HDF_STRING);
        CheckDlgButton(hwnd, IDC_INSERTHDBITMAP, hi.fmt & HDF_BITMAP);
        wsprintf(szTemp, szLongFilter, (DWORD)  hi.hbm);
        SetDlgItemText(hwnd, IDC_INSERTHBM, szTemp);        
        wsprintf(szTemp, "%04x", hi.fmt);
//      SetDlgItemInt(hwnd, IDC_INSERTFMT, hi.fmt, TRUE); 
        SetDlgItemText(hwnd, IDC_INSERTFMT, szTemp);
    }
    
    if (!pfr->NullpszText) {
        GlobalUnlock(hglb);
        GlobalFree(hglb); 
    }
/****
  wsprintf(szTemp, szLongFilter, hwndFind) ;
  SetDlgItemText(hwnd, ID_INSERTRET, szTemp) ;
**/
}
开发者ID:mingpen,项目名称:OpenNT,代码行数:76,代码来源:headget.c

示例11: RegisterClipboardFormat

void BookServerTest::testWord()
{
	//static const WCHAR kFilePath[] = LR"(F:\bk\physics\quantum mechanics\exam\2009\09北京大学量子力学(记忆版).doc)";
	DWORD rtfFormat = RegisterClipboardFormat(L"Rich Text Format");
	static const WCHAR kFilePath[] = LR"(e:\test.docx)";
	ComPtr<IMoniker> fileMoniker;
	auto hr = CreateFileMoniker(kFilePath, &fileMoniker);
	if (FAILED(hr))
		return;
	ComPtr<IBindCtx> pbc;
	CreateBindCtx(0, &pbc);
	ComPtr<IDataObject> dataObject;
	hr = fileMoniker->BindToObject(pbc, NULL, IID_IDataObject, (void**)&dataObject);
	if (FAILED(hr))
		return;

	ComPtr<IDataObject> dataObject2;
	hr = fileMoniker->BindToObject(pbc, NULL, IID_IDataObject, (void**)&dataObject2);
	if (FAILED(hr))
		return;

	{
		ComPtr<IEnumFORMATETC> enumFormat;
		auto hr = dataObject->EnumFormatEtc(DATADIR_GET, &enumFormat);
		if (FAILED(hr))
			return;
		FORMATETC format;
		std::vector<FORMATETC> getFormats;
		while ((hr = enumFormat->Next(1, &format, NULL)) == S_OK) {
			getFormats.push_back(format);
		}
		assert(getFormats.size() > 1);
	}

	{
		ComPtr<IEnumFORMATETC> enumFormat;
		auto hr = dataObject->EnumFormatEtc(DATADIR_SET, &enumFormat);
		if (FAILED(hr))
			return;
		FORMATETC format;
		std::vector<FORMATETC> setFormats;
		while ((hr = enumFormat->Next(1, &format, NULL)) == S_OK) {
			setFormats.push_back(format);
		}
		assert(setFormats.size() > 1);
	}

	{
		FORMATETC etc = { 0 };
		etc.cfFormat = CF_UNICODETEXT;
		etc.dwAspect = DVASPECT_CONTENT;
		etc.lindex = -1;
		etc.tymed = TYMED_HGLOBAL;
		STGMEDIUM stg = { 0 };
		hr = dataObject->GetData(&etc, &stg);
		if (FAILED(hr))
			return;
		auto ptr = GlobalLock(stg.hGlobal);
		assert(ptr);
	}


	{
		FORMATETC etc = { 0 };
		etc.cfFormat = CF_TEXT;
		etc.dwAspect = DVASPECT_CONTENT;
		etc.lindex = -1;
		etc.tymed = TYMED_HGLOBAL;
		STGMEDIUM stg = { 0 };
		hr = dataObject->GetData(&etc, &stg);
		if (FAILED(hr))
			return;
		//return gbk encoding.
		auto ptr = GlobalLock(stg.hGlobal);
		assert(ptr);
	}

	{
		FORMATETC etc = { 0 };
		etc.cfFormat = CF_TEXT;
		etc.dwAspect = DVASPECT_CONTENT;
		etc.lindex = -1;
		etc.tymed = TYMED_HGLOBAL;
		STGMEDIUM stg = { 0 };
		const static CHAR kContent[] = "how to zhangbi\r\n";
		auto hg = GlobalAlloc(GPTR, sizeof(kContent) + 1);
		auto ptr = (CHAR*)GlobalLock(hg);
		StringCchCopyA(ptr, sizeof(kContent), kContent);
		stg.tymed = TYMED_HGLOBAL;
		stg.hGlobal = hg;
		hr = dataObject->SetData(&etc, &stg, FALSE);
		if (FAILED(hr))
			return;
		assert(stg.lpszFileName);
		ReleaseStgMedium(&stg);
		ComQIPtr<IPersistFile> file = dataObject;
		hr = file->Save(NULL, TRUE);
		if (FAILED(hr))
			return;
	}
开发者ID:Jichao,项目名称:comtut,代码行数:100,代码来源:BookServerTest.cpp

示例12: wxLogTrace

// get data functions
STDMETHODIMP wxIDataObject::GetData(FORMATETC *pformatetcIn, STGMEDIUM *pmedium)
{
    wxLogTrace(wxTRACE_OleCalls, wxT("wxIDataObject::GetData"));

    // is data is in our format?
    HRESULT hr = QueryGetData(pformatetcIn);
    if ( FAILED(hr) )
        return hr;

    // for the bitmaps and metafiles we use the handles instead of global memory
    // to pass the data
    wxDataFormat format = (wxDataFormat::NativeFormat)pformatetcIn->cfFormat;
    format = HtmlFormatFixup(format);

    // is this system data?
    if ( GetSystemData(format, pmedium) )
    {
        // pmedium is already filled with corresponding data, so we're ready.
        return S_OK;
    }

    switch ( format )
    {
        case wxDF_BITMAP:
            pmedium->tymed = TYMED_GDI;
            break;

        case wxDF_ENHMETAFILE:
            pmedium->tymed = TYMED_ENHMF;
            break;

#ifndef __WXWINCE__
        case wxDF_METAFILE:
            pmedium->hGlobal = GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE,
                                           sizeof(METAFILEPICT));
            if ( !pmedium->hGlobal ) {
                wxLogLastError(wxT("GlobalAlloc"));
                return E_OUTOFMEMORY;
            }
            pmedium->tymed = TYMED_MFPICT;
            break;
#endif
        default:
            // alloc memory
            size_t size = m_pDataObject->GetDataSize(format);
            if ( !size ) {
                // it probably means that the method is just not implemented
                wxLogDebug(wxT("Invalid data size - can't be 0"));

                return DV_E_FORMATETC;
            }

            // we may need extra space for the buffer size
            size += m_pDataObject->GetBufferOffset( format );

            HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, size);
            if ( hGlobal == NULL ) {
                wxLogLastError(wxT("GlobalAlloc"));
                return E_OUTOFMEMORY;
            }

            // copy data
            pmedium->tymed   = TYMED_HGLOBAL;
            pmedium->hGlobal = hGlobal;
    }

    pmedium->pUnkForRelease = NULL;

    // do copy the data
    hr = GetDataHere(pformatetcIn, pmedium);
    if ( FAILED(hr) ) {
        // free resources we allocated
        if ( pmedium->tymed & (TYMED_HGLOBAL | TYMED_MFPICT) ) {
            GlobalFree(pmedium->hGlobal);
        }

        return hr;
    }

    return S_OK;
}
开发者ID:AdmiralCurtiss,项目名称:pcsx2,代码行数:82,代码来源:dataobj.cpp

示例13: ReadFileIntoMemory

LPLOCKBYTES ReadFileIntoMemory(const std::wstring& fileName)
{
    HRESULT hr = S_OK;
    HANDLE file = INVALID_HANDLE_VALUE;

    file = ::CreateFileW(fileName.c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
    if(INVALID_HANDLE_VALUE == file)
    {
        DWORD lastError = GetLastError();
        std::tostringstream msg;
        msg << _T("Failed to open [") << fileName << _T("] for reading its contents into memory, so we may read its custom properties") << std::ends;
        throw Workshare::System::SystemException(msg.str().c_str(), lastError);
    }

    try
    {
        unsigned long size = ::GetFileSize(file, NULL);
        HGLOBAL memory = GlobalAlloc(GPTR, size);
        if(NULL == memory)
        {
            DWORD lastError = GetLastError();
            std::tostringstream msg;
            msg << _T("Failed to allocate ") << size << _T(" bytes of memory for reading [") << fileName << _T("] into memory, so we may read its custom properties") << std::ends;
            throw Workshare::System::SystemException(msg.str().c_str(), lastError);
        }

        try
        {
            DWORD numberOfBytesRead = 0;
            BOOL ok = ::ReadFile(file, memory, size, &numberOfBytesRead, NULL);
            if(!ok)
            {
                DWORD lastError = GetLastError();
                std::tostringstream msg;
                msg << _T("Failed to read ") << size << _T(" bytes from [") << fileName << _T("] into a buffer that is ") << size << _T(" big, so we may read its custom properties") << std::ends;
                throw Workshare::System::SystemException(msg.str().c_str(), lastError);
            }

            if(size != numberOfBytesRead)
            {
                std::tostringstream msg;
                msg << _T("Failed to read all the ") << size << _T(" bytes from [") << fileName << _T("] into a buffer that is ") << size << _T(" big, so we may read its custom properties. Only ") << numberOfBytesRead << _T(" was read") << std::ends;
                throw Workshare::System::IO::IOException(msg.str().c_str());
            }

            LPLOCKBYTES lpBytes = NULL;
            hr = CreateILockBytesOnHGlobal(memory, TRUE, &lpBytes);
            if(FAILED(hr))
            {
                std::tostringstream msg;
                msg << _T("Failed to create an instance of ILockBytes from memory ") << size << _T(" bytes from [") << fileName << _T("] into a buffer that is ") << size << _T(" big, so we may read its custom properties. Only ") << numberOfBytesRead << _T(" was read") << std::ends;
                throw Workshare::System::IO::IOException(msg.str().c_str());
            }

            CloseHandle(file);
            return lpBytes;
        }
        catch(...)
        {
            GlobalFree(memory);
            throw;
        }
    }
    catch(...)
    {
        CloseHandle(file);
        throw;
    }
}
开发者ID:killbug2004,项目名称:WSProf,代码行数:69,代码来源:DominoConnector.cpp

示例14: test_marshal_HGLOBAL

static void test_marshal_HGLOBAL(void)
{
    USER_MARSHAL_CB umcb;
    MIDL_STUB_MESSAGE stub_msg;
    RPC_MESSAGE rpc_msg;
    unsigned char *buffer;
    ULONG size, block_size;
    HGLOBAL hglobal;
    HGLOBAL hglobal2;
    unsigned char *wirehglobal;
    int i;

    hglobal = NULL;
    init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, MSHCTX_LOCAL);
    size = HGLOBAL_UserSize(&umcb.Flags, 0, &hglobal);
    /* native is poorly programmed and allocates 4/8 bytes more than it needs to
     * here - Wine doesn't have to emulate that */
    ok((size == 8) || broken(size == 12) || broken(size == 16), "Size should be 8, instead of %d\n", size);
    buffer = HeapAlloc(GetProcessHeap(), 0, size);
    init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_LOCAL);
    HGLOBAL_UserMarshal(&umcb.Flags, buffer, &hglobal);
    wirehglobal = buffer;
    ok(*(ULONG *)wirehglobal == WDT_REMOTE_CALL, "Context should be WDT_REMOTE_CALL instead of 0x%08x\n", *(ULONG *)wirehglobal);
    wirehglobal += sizeof(ULONG);
    ok(*(ULONG *)wirehglobal == 0, "buffer+4 should be HGLOBAL\n");
    init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_LOCAL);
    HGLOBAL_UserUnmarshal(&umcb.Flags, buffer, &hglobal2);
    ok(hglobal2 == hglobal, "Didn't unmarshal properly\n");
    HeapFree(GetProcessHeap(), 0, buffer);
    init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, MSHCTX_LOCAL);
    HGLOBAL_UserFree(&umcb.Flags, &hglobal2);


    for(block_size = 0; block_size <= 17; block_size++)
    {
        ULONG actual_size, expected_size;

        hglobal = GlobalAlloc(0, block_size);
        buffer = GlobalLock(hglobal);
        for (i = 0; i < block_size; i++)
            buffer[i] = i;
        GlobalUnlock(hglobal);
        actual_size = GlobalSize(hglobal);
        expected_size = actual_size + 5 * sizeof(DWORD);
        trace("%d: actual size %d\n", block_size, actual_size);
        init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, MSHCTX_LOCAL);
        size = HGLOBAL_UserSize(&umcb.Flags, 0, &hglobal);
        /* native is poorly programmed and allocates 4/8 bytes more than it needs to
         * here - Wine doesn't have to emulate that */
        ok(size == expected_size ||
           broken(size == expected_size + 4) ||
           broken(size == expected_size + 8),
           "%d: got size %d\n", block_size, size);
        buffer = HeapAlloc(GetProcessHeap(), 0, size);
        init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_LOCAL);
        HGLOBAL_UserMarshal(&umcb.Flags, buffer, &hglobal);
        wirehglobal = buffer;
        ok(*(ULONG *)wirehglobal == WDT_REMOTE_CALL, "Context should be WDT_REMOTE_CALL instead of 0x%08x\n", *(ULONG *)wirehglobal);
        wirehglobal += sizeof(ULONG);
        ok(*(ULONG *)wirehglobal == (ULONG)(ULONG_PTR)hglobal, "buffer+0x4 should be HGLOBAL\n");
        wirehglobal += sizeof(ULONG);
        ok(*(ULONG *)wirehglobal == actual_size, "%d: buffer+0x8 %08x\n", block_size, *(ULONG *)wirehglobal);
        wirehglobal += sizeof(ULONG);
        ok(*(ULONG *)wirehglobal == (ULONG)(ULONG_PTR)hglobal, "buffer+0xc should be HGLOBAL\n");
        wirehglobal += sizeof(ULONG);
        ok(*(ULONG *)wirehglobal == actual_size, "%d: buffer+0x10 %08x\n", block_size, *(ULONG *)wirehglobal);
        wirehglobal += sizeof(ULONG);
        for (i = 0; i < block_size; i++)
            ok(wirehglobal[i] == i, "buffer+0x%x should be %d\n", 0x10 + i, i);

        init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_LOCAL);
        HGLOBAL_UserUnmarshal(&umcb.Flags, buffer, &hglobal2);
        ok(hglobal2 != NULL, "Didn't unmarshal properly\n");
        HeapFree(GetProcessHeap(), 0, buffer);
        init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, MSHCTX_LOCAL);
        HGLOBAL_UserFree(&umcb.Flags, &hglobal2);
        GlobalFree(hglobal);
    }
}
开发者ID:pstrealer,项目名称:wine,代码行数:79,代码来源:usrmarshal.c

示例15: SaveBmp

//VC下把HBITMAP保存为bmp图片   
BOOL  SaveBmp(HBITMAP     hBitmap, CString     FileName)
{
	HDC     hDC;
	//当前分辨率下每象素所占字节数         
	int     iBits;
	//位图中每象素所占字节数         
	WORD     wBitCount;
	//定义调色板大小,     位图中像素字节大小     ,位图文件大小     ,     写入文件字节数             
	DWORD     dwPaletteSize = 0, dwBmBitsSize = 0, dwDIBSize = 0, dwWritten = 0;
	//位图属性结构             
	BITMAP     Bitmap;
	//位图文件头结构         
	BITMAPFILEHEADER     bmfHdr;
	//位图信息头结构             
	BITMAPINFOHEADER     bi;
	//指向位图信息头结构                 
	LPBITMAPINFOHEADER     lpbi;
	//定义文件,分配内存句柄,调色板句柄             
	HANDLE     fh, hDib, hPal, hOldPal = NULL;

	//计算位图文件每个像素所占字节数             
	hDC = CreateDC(L"DISPLAY", NULL, NULL, NULL);
	iBits = GetDeviceCaps(hDC, BITSPIXEL)     *     GetDeviceCaps(hDC, PLANES);
	DeleteDC(hDC);
	if (iBits <= 1)
		wBitCount = 1;
	else  if (iBits <= 4)
		wBitCount = 4;
	else if (iBits <= 8)
		wBitCount = 8;
	else
		wBitCount = 24;

	GetObject(hBitmap, sizeof(Bitmap), (LPSTR)&Bitmap);
	bi.biSize = sizeof(BITMAPINFOHEADER);
	bi.biWidth = Bitmap.bmWidth;
	bi.biHeight = Bitmap.bmHeight;
	bi.biPlanes = 1;
	bi.biBitCount = wBitCount;
	bi.biCompression = BI_RGB;
	bi.biSizeImage = 0;
	bi.biXPelsPerMeter = 0;
	bi.biYPelsPerMeter = 0;
	bi.biClrImportant = 0;
	bi.biClrUsed = 0;

	dwBmBitsSize = ((Bitmap.bmWidth *wBitCount + 31) / 32) * 4 * Bitmap.bmHeight;

	//为位图内容分配内存             
	hDib = GlobalAlloc(GHND, dwBmBitsSize + dwPaletteSize + sizeof(BITMAPINFOHEADER));
	lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDib);
	*lpbi = bi;

	//     处理调色板                 
	hPal = GetStockObject(DEFAULT_PALETTE);
	if (hPal)
	{
		hDC = ::GetDC(NULL);
		hOldPal = ::SelectPalette(hDC, (HPALETTE)hPal, FALSE);
		RealizePalette(hDC);
	}

	//     获取该调色板下新的像素值             
	GetDIBits(hDC, hBitmap, 0, (UINT)Bitmap.bmHeight,
		(LPSTR)lpbi + sizeof(BITMAPINFOHEADER) + dwPaletteSize,
		(BITMAPINFO *)lpbi, DIB_RGB_COLORS);

	//恢复调色板                 
	if (hOldPal)
	{
		::SelectPalette(hDC, (HPALETTE)hOldPal, TRUE);
		RealizePalette(hDC);
		::ReleaseDC(NULL, hDC);
	}


	//创建位图文件                 
	fh = CreateFile(FileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
		FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);

	if (fh == INVALID_HANDLE_VALUE)         return     FALSE;

	//     设置位图文件头             
	bmfHdr.bfType = 0x4D42;     //     "BM"             
	dwDIBSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + dwPaletteSize + dwBmBitsSize;
	bmfHdr.bfSize = dwDIBSize;
	bmfHdr.bfReserved1 = 0;
	bmfHdr.bfReserved2 = 0;
	bmfHdr.bfOffBits = (DWORD)sizeof(BITMAPFILEHEADER) + (DWORD)sizeof(BITMAPINFOHEADER) + dwPaletteSize;
	//     写入位图文件头             
	WriteFile(fh, (LPSTR)&bmfHdr, sizeof(BITMAPFILEHEADER), &dwWritten, NULL);
	//     写入位图文件其余内容             
	WriteFile(fh, (LPSTR)lpbi, dwDIBSize, &dwWritten, NULL);
	//清除                 
	GlobalUnlock(hDib);
	GlobalFree(hDib);
	CloseHandle(fh);

	return     TRUE;
//.........这里部分代码省略.........
开发者ID:gao19920804,项目名称:ScreenShot,代码行数:101,代码来源:ScreenShot.cpp


注:本文中的GlobalAlloc函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。