为什么StretchBlt在Windows 2003中分配的内存是XP的两倍? [英] why StretchBlt allocated two times memory in windows 2003 than xp?

查看:91
本文介绍了为什么StretchBlt在Windows 2003中分配的内存是XP的两倍?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的虚拟打印驱动程序调用了此函数,以将bmp转换为EMF.

This function is called by my virtual print driver to convert bmp to EMF.

void GetEmfByBytes(BYTE * pBits, int iWidth, int iHeight, WCHAR* szPrinterName, WCHAR* szDestinationFile,DWORD rop=SRCCOPY)
{
    BITMAP bm;

    HDC hdcMem = CreateCompatibleDC(GetDC(NULL));
    HDC hPrinterDC = ::CreateDC(NULL,szPrinterName, NULL, NULL);

    BITMAPINFOHEADER bmih;
    memset(&bmih, 0, sizeof(BITMAPINFOHEADER));

    bmih.biSize = sizeof(BITMAPINFOHEADER);
    bmih.biBitCount = 1;
    bmih.biCompression = BI_RGB;
    bmih.biPlanes = 1;
    bmih.biWidth = iWidth;
    bmih.biHeight = iHeight;

    BITMAPINFO bmi;
    memset(&bmi, 0, sizeof(BITMAPINFO));

    bmi.bmiHeader = bmih;

    HBITMAP hBmp = ::CreateDIBitmap(hPrinterDC,&bmih,CBM_INIT,pBits,&bmi,0);

    GetObject(hBmp, sizeof(BITMAP), &bm );
    SelectObject(hdcMem, hBmp);
    HDC emfdc = CreateEnhMetaFile(hPrinterDC, szDestinationFile, NULL, L"");

    if(emfdc!=NULL){
        StretchBlt(emfdc,0, 0, bm.bmWidth, -bm.bmHeight, hdcMem, 0, 0, bm.bmWidth, bm.bmHeight, rop);// From task     manager I found the memory of spoolsv.exe increased 
        // 4M in xp, while 8M in windows 2003.
        //DeleteDC(emfdc);
        HENHMETAFILE hEMFFile = CloseEnhMetaFile(emfdc);// 4M memory were released in both xp and windows 2003. So     4M memory were still not released in windows 2003. Memory Leak!
        DeleteEnhMetaFile(hEMFFile);
        //DeleteDC(emfdc);
    }else{
        logOut( wstring(L"can't create emf")+szDestinationFile );
    }

    DeleteDC(hPrinterDC);
    DeleteDC(hdcMem);
    DeleteObject(hBmp);
}




有人知道为什么吗?多谢!请〜!




anyone knows why? thanks a lot! Please~!

推荐答案

也许这文章 [ ^ ]可以为您提供帮助确定原因.
Perhaps this article[^] can help you determine the cause.


今天,当我在Windows 2003中仅安装一次虚拟打印机时,内存与xp相同.但是,当我在Windows 2003中安装两个以上的虚拟打印机时,StretchBlt在Windows 2003中分配的内存是xp的两倍.
Today I find when I just install my virtual printer once in windows 2003, the memory become the same as xp. But when I install more than two same virtual printer in windows 2003, StretchBlt allocated two times memory in windows 2003 than xp.


我终于找到了问题. StretchBlt的srcDc和desDc必须兼容.所以
HDC hdcMem = CreateCompatibleDC(GetDC(NULL));
HDC hPrinterDC = :: CreateDC(NULL,szPrinterName,NULL,NULL);
应该更改如下:
HDC hPrinterDC = :: CreateDC(NULL,szPrinterName,NULL,NULL);
HDC hdcMem = CreateCompatibleDC(hPrinterDC);
但是问题并没有在xp和Windows 2000上发生.
I finally find the problem. The srcDc and desDc of StretchBlt must be compatible. So
HDC hdcMem = CreateCompatibleDC(GetDC(NULL));
HDC hPrinterDC = ::CreateDC(NULL,szPrinterName, NULL, NULL);
should be changed as following:
HDC hPrinterDC = ::CreateDC(NULL,szPrinterName, NULL, NULL);
HDC hdcMem = CreateCompatibleDC(hPrinterDC );
But the problem didn''t take place at xp and windows 2000.


这篇关于为什么StretchBlt在Windows 2003中分配的内存是XP的两倍?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆