+ Reply to Thread
Results 1 to 2 of 2

Thread: Reading unicode data from a clipboard

  1. #1

    Reading unicode data from a clipboard

    I can read text data from clipboard. but how to read Unicode data from the clipboard? Following code does not work:

    Code:
    void ReadClipboardData()
    {
    	if (::OpenClipboard(NULL))
    	{
    		HANDLE hClipboard = ::GetClipboardData(CF_TEXT) ;
    		if (NULL != hClipboard)
    		{
    			//....
    			wchar_t* pClipboard = (wchar_t *) ::GlobalLock(hClipboard) ;
    		}
    		::CloseClipboard() ;
    	}
    }
    Please help with this.

  2. #2
    Junior Member
    Join Date
    May 2012
    Posts
    27
    You are using CF_TEXT rather than CF_UNICODETEXT.

    Example:
    Code:
    wchar_t * ReadClipboardUnicodeData()
    {
    	wchar_t* pClipboardData = NULL ;
    	
    	if (::OpenClipboard(NULL))
    	{
    		HANDLE hClipboardData = ::GetClipboardData(CF_UNICODETEXT) ;
    		if (NULL != hClipboardData)
    		{
    			wchar_t* pClipboardBuffer = (wchar_t *) ::GlobalLock(hClipboardData) ;
    			pClipboardData = new wchar_t[wcslen(pClipboardBuffer) + 2] ;
    			wcscpy(pClipboardData, pClipboardBuffer) ;
    			::GlobalUnlock(pClipboardData) ;
    		}
    		::CloseClipboard() ;
    	}
    
    	return pClipboardData ;
    }

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts