Thread: reading from Windows clipboard

  1. #1

    Exclamation reading from Windows clipboard

    I have read the other posts on the board and none of them really solve my problem.

    Code:
    BOOL ClipboardPaste(HWND hWindow)
    {
    	 static PTSTR pText ;
         BOOL         bEnable ;
         HGLOBAL      hGlobal ;
         HDC          hdc ;
         LPTSTR        pGlobal ;
         BOOL         bAvailable;
       
    			   
    			   OpenClipboard (hWindow) ;
                   
    			   bAvailable = IsClipboardFormatAvailable (CF_TEXT) ;
                   if (hGlobal = GetClipboardData (CF_TEXT))
                   {
                      pGlobal = GlobalLock(hGlobal) ;
                        if (pText)
                        {
                             free (pText) ;
                             pText = NULL ;
                        }
                      pText =   GlobalSize(hGlobal);
                        lstrcpy (pText, pGlobal) ;
                        InvalidateRect (hWindow, NULL, TRUE) ;
                   }
                   CloseClipboard () ;
                   return 0 ;
    
    }
    when i try to compile i get 2 errors:

    for pGlobal = GlobalLock(hGlobal);
    c:\documents and settings\administrator.sean\desktop\csedit\header. h(170) : error C2440: '=' : cannot convert from 'void *' to 'char *'

    for pText = GlobalSize(hGlobal);
    c:\documents and settings\administrator.sean\desktop\csedit\header. h(176) : error C2440: '=' : cannot convert from 'unsigned long' to 'char *'

    could anyone please help me?
    Last edited by unanimous; 11-16-2002 at 12:33 PM.

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Change the file extension to 'c' to compile as a 'c' program or cast those values to the type required as explained by the error messages.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    When I cast it i get a "debug assertion failed" when i try to paste anything

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    You need to allocate memory for pText prior to using it. As written, you are setting pText to point to an address given by the size of hGlobal (your data) which will understandably cause problems as soon as you attempt to use that pointer.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Script errors - bool unrecognized and struct issues
    By ulillillia in forum Windows Programming
    Replies: 10
    Last Post: 12-18-2006, 04:44 AM
  2. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM
  3. IE 6 status bar
    By DavidP in forum Tech Board
    Replies: 15
    Last Post: 10-23-2002, 05:31 PM
  4. Manipulating the Windows Clipboard
    By Johno in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2002, 09:37 AM