Click here to Skip to main content
       

ATL / WTL / STL

 
QuestionSTL map issue in VS2010 PinmemberSubhash Madhukar30-Oct-12 4:47 
AnswerRe: STL map issue in VS2010 PinmvpRichard MacCutchan30-Oct-12 7:04 
Questionhow do i copy a CImage DIB to clipboard PinmemberMember 951640015-Oct-12 12:15 
AnswerRe: how do i copy a CImage DIB to clipboard PinmemberAndrew Cherednik15-Oct-12 12:41 
It fails because the memory allocated by GlobalAlloc is not enough. See, how you use sizeof(BITMAPINFO) + w * h * 3 value to allocate memory, and then you are trying to calculate the m_dwSizeImage value, which is much greater then requested.
 
You have got two options:
Either move this chunk of code after you have calculated the image size, so that your code becomes:
    DWORD dwBytes = ((DWORD) w * Bpp) / 32;
    
    if(((DWORD) w * Bpp) % 32) {
       dwBytes++;
    }
    dwBytes *= 4;
   
    unsigned long m_dwSizeImage = dwBytes * h; // no compression

    void* pBits = tmpImage.GetBits();
    HANDLE hData = ::GlobalAlloc (GMEM_MOVEABLE, sizeof(BITMAPINFO) + m_dwSizeImage);
    LPVOID pData = (LPVOID) ::GlobalLock (hData);
    LPBYTE p_imagebits;
    p_imagebits  = (LPBYTE)pData + sizeof(BITMAPINFO);
    
 
    memcpy(pData,&bmInfo,sizeof(BITMAPINFO));
    memcpy (p_imagebits, pBits, m_dwSizeImage);
           
 

Or, just use a solution[^] from Codeguru
 
BTW, it looks like you have calculated the m_dwImageSize incorrectly anyway
QuestionWhy does this fail - CFile / SeekToEnd? [modified] Pinmembercharlieg10-Oct-12 7:43 
AnswerRe: Why does this fail - CFile / SeekToEnd? Pinmembercharlieg10-Oct-12 10:31 
AnswerRe: Why does this fail - CFile / SeekToEnd? PinmemberAndrew Cherednik10-Oct-12 12:23 
GeneralRe: Why does this fail - CFile / SeekToEnd? Pinmembercharlieg11-Oct-12 3:20 
AnswerRe: Why does this fail - CFile / SeekToEnd? PinmvpRichard MacCutchan10-Oct-12 22:45 
GeneralRe: Why does this fail - CFile / SeekToEnd? Pinmembercharlieg11-Oct-12 3:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web01 | 2.8.141223.1 | Last Updated 22 Dec 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid