-
Clipboard problem
Hi All,
I am trying to save the clipboard content as a bmp file. I tried like this:
Code:
HANDLE hBmp;
OpenClipboard();
hBmp = GetClipboardData(CF_DIB);
if(hBmp)
{
if (WriteDIB("c:\\TEST.BMP",GetClipboardData(CF_DIB)) == TRUE)
{
MessageBox("Success","BMP Written",NULL);
}
else
{
MessageBox("Failed","BMP Write",NULL);
}
EmptyClipboard ();
}
else
{
printerror(GetLastError());
}
CloseClipboard();
void printerror(long err)
{
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,NULL,err,MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),(LPTSTR)&lpMsgBuf,30,NULL);
MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION );
}
I am getting NULL in hBmp. So if condition fails. I tried to get the error code. But error message says "Function completed successfully". Can anyone help me where i went wrong??
Thanks in advance,
Saravanan.
-
I can't see why GetLastError() would return that value. Very strange.
Note that you should delete lpMsgBuffer to prevent a memory leak.
-
Hi Benny,
I tried with other constant like CF_BITMAP. Again I am getting hBmp to zero.
But one thing i noticed. If I place CF_TEXT in GetClipboardData() then I am getting a valid handle i.e. valid hBmp. But since it is in text I am not able to write the contents as bmp file. So whats really going on here.
Can anyone help me!!
Saravanan.