Getting Clipboard Handle using GetClipboardData in C#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Roohi

    Getting Clipboard Handle using GetClipboardData in C#

    hi

    I am trying to copy an image to a clipboard and then get a
    handle to the clipboard using API calls GetClipboardDat a().

    Following is the snippet of our code. Could any one please
    point out what am I missing here since I never get the
    handle to the object on clipboard

    <snippet>

    OpenClipboard(0 );

    DataObject m_data = new DataObject();

    m_data.SetData( DataFormats.Dib ,imgCardImage.I mage);

    Clipboard.SetDa taObject(m_data ,false);

    hDib = GetClipboardDat a(CF_DIB); // CF_DIB = 8;

    </snippet>


    hDib returned is always 0 where it actually had to return
    a handle to the clipboard;

    Thanks in Advance.

    ~Roohi
  • Morten Wennevik

    #2
    Re: Getting Clipboard Handle using GetClipboardDat a in C#

    Not familiar with GetClipboardDat a.
    Why do you need a handle to it instead of using .NET's
    ClipBoard.GetDa taObject to retrieve it?

    --
    Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/

    Comment

    • Roohi

      #3
      Re: Getting Clipboard Handle using GetClipboardDat a in C#

      I need to pass this handle to some other API which accepts
      handle to the clipboard as a parameter

      Hence I need it

      Thanks
      [color=blue]
      >-----Original Message-----
      >Not familiar with GetClipboardDat a.
      >Why do you need a handle to it instead of using .NET's
      >ClipBoard.GetD ataObject to retrieve it?
      >
      >--
      >Using M2, Opera's revolutionary e-mail client:[/color]
      http://www.opera.com/m2/[color=blue]
      >.
      >[/color]

      Comment

      • Morten Wennevik

        #4
        Re: Getting Clipboard Handle using GetClipboardDat a in C#

        Hm, maybe Clipboard.SetDa taObject() closes the clipboard you opened with
        OpenClipboard() .
        Try moving OpenClipBoard(0 ); after SetDataObject()


        --
        Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/

        Comment

        • Roohi

          #5
          Re: Getting Clipboard Handle using GetClipboardDat a in C#

          I tried doing that, but still the same problem

          Roohi
          [color=blue]
          >-----Original Message-----
          >Hm, maybe Clipboard.SetDa taObject() closes the clipboard[/color]
          you opened with[color=blue]
          >OpenClipboard( ).
          >Try moving OpenClipBoard(0 ); after SetDataObject()
          >
          >
          >--
          >Using M2, Opera's revolutionary e-mail client:[/color]
          http://www.opera.com/m2/[color=blue]
          >.
          >[/color]

          Comment

          • Jeff Gaines

            #6
            Re: Getting Clipboard Handle using GetClipboardDat a in C#

            On Wed, 12 Nov 2003 02:25:33 -0800, "Roohi"
            <angelic_soul_i n@hotmail.com> wrote:
            [color=blue]
            >hi
            >
            >I am trying to copy an image to a clipboard and then get a
            >handle to the clipboard using API calls GetClipboardDat a().
            >
            >~Roohi[/color]

            Roohi

            Can you modify this to do what you need:

            public static bool JCopyFilesToCli pboard(string[] strFiles, POINT pt)
            {
            bool blnReturn = false;
            byte[] bData;
            DROPFILES df = new DROPFILES();
            int intChar, intFile, intDataLen, intPos;
            IntPtr ipGlobal = IntPtr.Zero;

            // Calculate total data length
            intDataLen = 0;
            for(intFile = 0; intFile <= strFiles.GetUpp erBound(0);
            intFile++)
            intDataLen += strFiles[intFile].Length + 1;

            // Terminating double zero
            intDataLen++;

            bData = new Byte[intDataLen];
            intPos = 0;

            // Build null terminated list of files
            for(intFile = 0; intFile <= strFiles.GetUpp erBound(0);
            intFile++)
            {
            for(intChar = 0; intChar < strFiles[intFile].Length;
            intChar++)
            {
            bData[intPos++] = (byte)strFiles[intFile][intChar];
            }
            bData[intPos++] = 0;
            }
            // Terminating double zero
            bData[intPos++] = 0;

            // Allocate and get pointer to global memory
            int intTotalLen = Marshal.SizeOf( df) + intDataLen;
            ipGlobal = Marshal.AllocHG lobal(intTotalL en);

            if(ipGlobal == IntPtr.Zero)
            return false;

            // Build DROPFILES structure in global memory.
            df.pFiles = Marshal.SizeOf( df);
            df.pt = pt;
            df.fNC = false;
            df.fWide = 0;
            Marshal.Structu reToPtr(df, ipGlobal, true);
            IntPtr ipNew = new IntPtr(ipGlobal .ToInt32() +
            Marshal.SizeOf( df));
            Marshal.Copy(bD ata, 0, ipNew, intDataLen);

            // Open and empty clipboard
            if(!OpenClipboa rd(IntPtr.Zero) )
            return false;

            EmptyClipboard( );

            // Copy data to clipboard
            blnReturn = (SetClipboardDa ta(CF_HDROP, ipGlobal) !=
            IntPtr.Zero);
            if(!blnReturn)
            Marshal.FreeHGl obal(ipGlobal);

            // Clean up
            CloseClipboard( );
            // Clipboard responsible for freeing memory
            // Marshal.FreeHGl obal(ipGlobal);

            return blnReturn;
            }

            It's a different file format but the principle is similar.

            --
            Jeff Gaines Damerham Hampshire UK

            Comment

            • Jeff Gaines

              #7
              Re: Getting Clipboard Handle using GetClipboardDat a in C#

              On Wed, 12 Nov 2003 02:25:33 -0800, "Roohi"
              <angelic_soul_i n@hotmail.com> wrote:
              [color=blue]
              >hi
              >
              >I am trying to copy an image to a clipboard and then get a
              >handle to the clipboard using API calls GetClipboardDat a().
              >
              >Following is the snippet of our code. Could any one please
              >point out what am I missing here since I never get the
              >handle to the object on clipboard
              >
              >
              >hDib returned is always 0 where it actually had to return
              >a handle to the clipboard;
              >
              >Thanks in Advance.
              >
              >~Roohi[/color]

              Roohi

              I am not sure now if my earlier post answers your question :-(

              I have tried what you are doing - you must call open clipboard before
              trying to get the handle to the data. Is the clipboard still open when
              you make this call or have you already closed it?

              --
              Jeff Gaines Damerham Hampshire UK

              Comment

              Working...