Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Run-Time Check Failure when copying a graph image to the clipboard

I am trying to copy my NiGraph to the clipboard. I have followed the example graphtoClipboard example.

When the function exits in Visual Studio 2003 I get a
Run-Time Check Failure #2 - Stack around the variable 'niPicture' was corrupted.

My code is below

void CESCView::OnEditCopy()
{
CNiPicture niPicture;

niPicture = m_NIGraphCellV.ControlImage();

::OpenClipboard(NULL);
::EmptyClipboard();
::SetClipboardData(
CF_ENHMETAFILE,
::CopyEnhMetaFile(reinterpret_cast(niPicture.Handle), NULL)
);
::CloseClipboard();
}
0 Kudos
Message 1 of 3
(3,386 Views)
Hi,

First, does the example you are referring to does run properly? Your code is nearly identical to it, with the exception of how niPicture is declared (and this is functionally the same). I have run the example and do not see this error. Perhaps I am doing something differently than you are.

Another difference I noticed was the m_NIGraphCellV. Is this object of type CNiGraph or is it another type? It sounds like that is the case, but I am just making sure.

If the example works fine for you and only your code is giving this problem, what other differences exist in your code that are worth noting?

Best Regards,
Allen P.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 3
(3,385 Views)
It does copy, but I am worried about the reliability of my program when I get this message.

Things to note are:
I only see this message in the Debug Version. m_NIGraphCellV is a CNiGraph.
I get a Compiler Warning (level 1) C4312 "c:\Projects\Hii\Esc pc\ESC View.cpp(694): warning C4312: 'reinterpret_cast' : conversion from 'long' to 'HENHMETAFILE' of greater size
"

Is there any other way to get a HENHMETAFILE or a HMETAFILE (non-enhanced version)?
0 Kudos
Message 3 of 3
(3,386 Views)