reading from Windows clipboard

This is a discussion on reading from Windows clipboard within the Windows Programming forums, part of the Platform Specific Boards category; I have read the other posts on the board and none of them really solve my problem. Code: BOOL ClipboardPaste(HWND ...

  1. #1
    Perverted unanimous's Avatar
    Join Date
    Oct 2001
    Posts
    336

    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.
    Give me a bad reputation!!!

  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
    Perverted unanimous's Avatar
    Join Date
    Oct 2001
    Posts
    336
    When I cast it i get a "debug assertion failed" when i try to paste anything
    Give me a bad reputation!!!

  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, 06:31 PM
  4. Manipulating the Windows Clipboard
    By Johno in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2002, 10:37 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21