In my program MFC Doc/view one view constantly displaying what the camera is "seeing". After some event I want to show in the other window - dialog the image that has been in the view in the moment of event.

I have code in Dialog window that succesfully draws pictures from disk. However it starts it's work with Handle and "LoadImage". When I try to pass a HANDLE from view no errors occure but no picture displays. The same situation when I pass CBitmap * with some modification of code.
Exploring structures I found that every bit of data like "Height", "Width" goes fine. But it seemed to me that there are some problems with pointer to picture data. Si I decided to copy data from pointer in view to pointer of picture data in dialog manualy with memcpy()

void CEx07bView::OnAppAbout()
    CClientDC dc(this); 
    CBitmap *pB;
    BITMAP bm;
    pB = dc.GetCurrentBitmap();

    CAboutDlg aboutDlg(bm); //bm - just some flag for tetsing

    aboutDlg.picture.tBm.bmBitsPixel = bm.bmBitsPixel;
    aboutDlg.picture.tBm.bmHeight = bm.bmHeight;
    aboutDlg.picture.tBm.bmPlanes = bm.bmPlanes;
    aboutDlg.picture.tBm.bmType = bm.bmType;
    aboutDlg.picture.tBm.bmWidth = bm.bmWidth;
    aboutDlg.picture.tBm.bmWidthBytes = bm.bmWidthBytes;
    memcpy(aboutDlg.picture.tBm.bmBits,bm.bmBits,((((aboutDlg.picture.tBm.bmWidth * (aboutDlg.picture.tBm.bmPlanes * aboutDlg.picture.tBm.bmBitsPixel)) + 31) & ~31) / 8)* aboutDlg.picture.tBm.bmHeight);  

And when I get "Access violation writing location 0x000000a4". 0x000000a4 - is the start address of tBm.bmBits by the way.

So questions)
What can be a good conception of realising my idea, generally? Did I choose right strategy or i should solve this problems in some other way? Just In common words, can someone show me the goodstyle direction or so?

And just practice question about this violation in memcpy. Howto copy this bits correctly in physically another memory in ohter structure?

Thanks in advance!

Hmmm, I guess problem with memcpy() refered to the fact that before "doModal()" nothing exists in Dialog-class?..

No, I made first bitmap structure "super" global - the same error.

Edited 4 Years Ago by 330xi: after testing

pB-GetBitmapBits(size,aboutDlg.picture.tBm.bmBits) instead memcpy doesn't help, still nothig is in dialogwindow(

Edited 4 Years Ago by 330xi

Actually I need Ideas or examples to copy picture from one dc to another through some buffer. Because without buffer I've got already dynamic recursion version of displaying image in another window exp. But I need a static picture before dialog appears

This article has been dead for over six months. Start a new discussion instead.