Thread: Clipboard problem

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    102

    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.
    Saravanan.T.S.
    Beginner.

  2. #2
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    I can't see why GetLastError() would return that value. Very strange.

    Note that you should delete lpMsgBuffer to prevent a memory leak.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  3. #3
    Registered User
    Join Date
    Jul 2003
    Posts
    102
    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.
    Saravanan.T.S.
    Beginner.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM