Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Problem with SetClipboardData on Win98 [modified]

Problem with SetClipboardData on Win98 [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
12 Posts 9 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S SachinBhave

    I have code written as below : CString csText; HANDLE hData=NULL; m_emailAddress.GetWindowText( csText ); if( (hData=GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, (csText.GetLength()+1) )) ) { LPVOID lpLockedMemory=NULL; lpLockedMemory = GlobalLock( hData ); CopyMemory( lpLockedMemory, csText.GetBuffer(csText.GetLength()), csText.GetLength() ); if( SetClipboardData( CF_TEXT, lpLockedMemory ) == NULL ) { AfxMessageBox( "Unable to set Clipboard data" ); GlobalUnlock( lpLockedMemory ); lpLockedMemory = NULL; CloseClipboard(); return; } } Now, this code works fine on Winxp, but for Win98 I get NULL as return value of SetClipboardData(). Can anyone help on this? -- modified at 4:03 Thursday 24th August, 2006

    A Offline
    A Offline
    Anna Jayne Metcalfe
    wrote on last edited by
    #2

    Yes, but not in the Lounge. That's why there's a red "No Programming Quesions, Please" sign at the top of the page... Post in the correct forum and you might just get some assistance with your problem.

    Anna :rose: Currently working mostly on: Visual Lint :cool: Anna's Place | Tears and Laughter "Be yourself - not what others think you should be" - Marcia Graesch "Anna's just a sexy-looking lesbian tart" - A friend, trying to wind me up. It didn't work.

    1 Reply Last reply
    0
    • S SachinBhave

      I have code written as below : CString csText; HANDLE hData=NULL; m_emailAddress.GetWindowText( csText ); if( (hData=GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, (csText.GetLength()+1) )) ) { LPVOID lpLockedMemory=NULL; lpLockedMemory = GlobalLock( hData ); CopyMemory( lpLockedMemory, csText.GetBuffer(csText.GetLength()), csText.GetLength() ); if( SetClipboardData( CF_TEXT, lpLockedMemory ) == NULL ) { AfxMessageBox( "Unable to set Clipboard data" ); GlobalUnlock( lpLockedMemory ); lpLockedMemory = NULL; CloseClipboard(); return; } } Now, this code works fine on Winxp, but for Win98 I get NULL as return value of SetClipboardData(). Can anyone help on this? -- modified at 4:03 Thursday 24th August, 2006

      E Offline
      E Offline
      Eytukan
      wrote on last edited by
      #3

      sachinbhave wrote:

      this code works fine on Winxp

      Then why not you stick to WinXp?:~ :rolleyes:


      --[:jig:]-- [My Current Status]

      1 Reply Last reply
      0
      • S SachinBhave

        I have code written as below : CString csText; HANDLE hData=NULL; m_emailAddress.GetWindowText( csText ); if( (hData=GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, (csText.GetLength()+1) )) ) { LPVOID lpLockedMemory=NULL; lpLockedMemory = GlobalLock( hData ); CopyMemory( lpLockedMemory, csText.GetBuffer(csText.GetLength()), csText.GetLength() ); if( SetClipboardData( CF_TEXT, lpLockedMemory ) == NULL ) { AfxMessageBox( "Unable to set Clipboard data" ); GlobalUnlock( lpLockedMemory ); lpLockedMemory = NULL; CloseClipboard(); return; } } Now, this code works fine on Winxp, but for Win98 I get NULL as return value of SetClipboardData(). Can anyone help on this? -- modified at 4:03 Thursday 24th August, 2006

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #4

        I'm going to save you from yourself and move this to the right forum. In future, please don't ask programming questions in the lounge.

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

        R 1 Reply Last reply
        0
        • S SachinBhave

          I have code written as below : CString csText; HANDLE hData=NULL; m_emailAddress.GetWindowText( csText ); if( (hData=GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, (csText.GetLength()+1) )) ) { LPVOID lpLockedMemory=NULL; lpLockedMemory = GlobalLock( hData ); CopyMemory( lpLockedMemory, csText.GetBuffer(csText.GetLength()), csText.GetLength() ); if( SetClipboardData( CF_TEXT, lpLockedMemory ) == NULL ) { AfxMessageBox( "Unable to set Clipboard data" ); GlobalUnlock( lpLockedMemory ); lpLockedMemory = NULL; CloseClipboard(); return; } } Now, this code works fine on Winxp, but for Win98 I get NULL as return value of SetClipboardData(). Can anyone help on this? -- modified at 4:03 Thursday 24th August, 2006

          P Offline
          P Offline
          prasad_som
          wrote on last edited by
          #5

          sachinbhave wrote:

          but for Win98 I get NULL as return value of SetClipboardData().

          No win98 system , to check this. Can you use GetLastError to check what error its returning.

          Prasad Notifier using ATL

          1 Reply Last reply
          0
          • C Christian Graus

            I'm going to save you from yourself and move this to the right forum. In future, please don't ask programming questions in the lounge.

            Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

            R Offline
            R Offline
            Rage
            wrote on last edited by
            #6

            Christian Graus wrote:

            move this to the right forum

            What work does this require ? I mean, I have no knowledge of databasis and SQL and so, but is this done easily or do you have to dig somewhere to find the thread and reput it in another table ?

            ~RaGE();

            I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus

            C 1 Reply Last reply
            0
            • R Rage

              Christian Graus wrote:

              move this to the right forum

              What work does this require ? I mean, I have no knowledge of databasis and SQL and so, but is this done easily or do you have to dig somewhere to find the thread and reput it in another table ?

              ~RaGE();

              I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #7

              Well, the first step would be to work here :-) I made the comment because I thought I was going to be the first ( and only lounge ) reply, and I wanted the OP to know that they had posted in the wrong spot still.

              Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

              R 1 Reply Last reply
              0
              • S SachinBhave

                I have code written as below : CString csText; HANDLE hData=NULL; m_emailAddress.GetWindowText( csText ); if( (hData=GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, (csText.GetLength()+1) )) ) { LPVOID lpLockedMemory=NULL; lpLockedMemory = GlobalLock( hData ); CopyMemory( lpLockedMemory, csText.GetBuffer(csText.GetLength()), csText.GetLength() ); if( SetClipboardData( CF_TEXT, lpLockedMemory ) == NULL ) { AfxMessageBox( "Unable to set Clipboard data" ); GlobalUnlock( lpLockedMemory ); lpLockedMemory = NULL; CloseClipboard(); return; } } Now, this code works fine on Winxp, but for Win98 I get NULL as return value of SetClipboardData(). Can anyone help on this? -- modified at 4:03 Thursday 24th August, 2006

                M Offline
                M Offline
                Michael Dunn
                wrote on last edited by
                #8

                Your memory management is a bit off. Call GlobalUnlock() before SetClipboardData(). If SetClipboardData() succeeds, the clipboard owns the memory, so you're done. If it fails, you need to GlobalFree() the memory.

                --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

                1 Reply Last reply
                0
                • C Christian Graus

                  Well, the first step would be to work here :-) I made the comment because I thought I was going to be the first ( and only lounge ) reply, and I wanted the OP to know that they had posted in the wrong spot still.

                  Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

                  R Offline
                  R Offline
                  Rage
                  wrote on last edited by
                  #9

                  Christian Graus wrote:

                  would be to work here

                  It was not my intention to do it myself, only wanted to nkow how this works...

                  ~RaGE();

                  I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus

                  C 1 Reply Last reply
                  0
                  • R Rage

                    Christian Graus wrote:

                    would be to work here

                    It was not my intention to do it myself, only wanted to nkow how this works...

                    ~RaGE();

                    I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus

                    C Offline
                    C Offline
                    Christian Graus
                    wrote on last edited by
                    #10

                    Fair enough - well, as an employee, I get UI to do that, I don't need to be messing with any DB tables directly.

                    Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

                    1 Reply Last reply
                    0
                    • S SachinBhave

                      I have code written as below : CString csText; HANDLE hData=NULL; m_emailAddress.GetWindowText( csText ); if( (hData=GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, (csText.GetLength()+1) )) ) { LPVOID lpLockedMemory=NULL; lpLockedMemory = GlobalLock( hData ); CopyMemory( lpLockedMemory, csText.GetBuffer(csText.GetLength()), csText.GetLength() ); if( SetClipboardData( CF_TEXT, lpLockedMemory ) == NULL ) { AfxMessageBox( "Unable to set Clipboard data" ); GlobalUnlock( lpLockedMemory ); lpLockedMemory = NULL; CloseClipboard(); return; } } Now, this code works fine on Winxp, but for Win98 I get NULL as return value of SetClipboardData(). Can anyone help on this? -- modified at 4:03 Thursday 24th August, 2006

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #11

                      sachinbhave wrote:

                      CopyMemory( lpLockedMemory, csText.GetBuffer(csText.GetLength()), csText.GetLength() );

                      It is not necessary to call GetBuffer() since you are not modifying csText.

                      sachinbhave wrote:

                      I get NULL as return value of SetClipboardData().

                      Which means you should be calling GetLastError() to find out why.

                      sachinbhave wrote:

                      GlobalUnlock( lpLockedMemory );

                      You should be calling this function regardless of whether SetClipboardData() fails or not.

                      sachinbhave wrote:

                      CloseClipboard();

                      There's no reason to call this if SetClipboardData() fails. Nothing is open at that point.


                      "Money talks. When my money starts to talk, I get a bill to shut it up." - Frank

                      "Judge not by the eye but by the heart." - Native American Proverb

                      1 Reply Last reply
                      0
                      • S SachinBhave

                        I have code written as below : CString csText; HANDLE hData=NULL; m_emailAddress.GetWindowText( csText ); if( (hData=GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, (csText.GetLength()+1) )) ) { LPVOID lpLockedMemory=NULL; lpLockedMemory = GlobalLock( hData ); CopyMemory( lpLockedMemory, csText.GetBuffer(csText.GetLength()), csText.GetLength() ); if( SetClipboardData( CF_TEXT, lpLockedMemory ) == NULL ) { AfxMessageBox( "Unable to set Clipboard data" ); GlobalUnlock( lpLockedMemory ); lpLockedMemory = NULL; CloseClipboard(); return; } } Now, this code works fine on Winxp, but for Win98 I get NULL as return value of SetClipboardData(). Can anyone help on this? -- modified at 4:03 Thursday 24th August, 2006

                        H Offline
                        H Offline
                        Hamid Taebi
                        wrote on last edited by
                        #12

                        Did you use from GetLastError for see error

                        _**


                        **_

                        WhiteSky


                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups