Copying to the clipboard

I currently have an application that draws to a DC (CDC to be specific) and I need to implement a Copy function. The message handlers, etc. are all in place, however, I can't seem to get things to the ClipBoard. Below is my code. I think it is self-explanatory. The code runs normally but when I try to paste into MS Word, for example, I get an error stating "the instruction at "0x00000017" referenced memory at "0x00000017". The memory could not be "read" followed by "There is not enough memory or disk space to complete the operation."

Any tips are GREATLY appreciated.


COleDataSource dataSource; //object to contain the data
CBitmap *oldBitmap, newBitmap; //bitmaps for the DC
CDC imageDC; //DC to hold the drawings
CClientDC viewDC(this); //clientDC which effectively holds the specifics of the current View

STGMEDIUM *dataContainer; //contains the data passed to the clipboard
dataContainer = new STGMEDIUM;

imageDC.CreateCompatibleDC(&viewDC); //create a DC compatible with the current view
newBitmap.CreateCompatibleBitmap(&imageDC, 500, 500); //create a bitmap

//select in the bitmap in so I can draw on it
oldBitmap = imageDC.SelectObject(&newBitmap);

//execute this view's draw operations

//get the bitmap out
oldBitmap = imageDC.SelectObject(oldBitmap);
//manipulate the data into the proper format to load onto the clipboard
dataContainer->tymed = TYMED_GDI;
dataContainer->hBitmap = (HBITMAP)(*oldBitmap);
dataSource.CacheData(CF_BITMAP, dataContainer);


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!