C# and handle to Clipboard


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

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

DataObject m_data = new DataObject();
hDib = GetClipboardData(CF_DIB); // CF_DIB = 8;

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

Thanks in Advance.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Do you have to use the API calls. .Net Framework contains some Clipboard classes.

For example see



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jayu_is_hereAuthor Commented:

We need a handle/pointer to the image in the memory. We need to pass this pointer to another API which expects a pointer to the image to store the image.


try this:

namespace vascov.xx.ClipboardProb
      public class ClipHelper
            [ DllImport( "user32.dll" ) ]
            extern static bool OpenClipboard( IntPtr hWnd );

            [ DllImport( "user32.dll" ) ]
            extern static bool CloseClipboard();

            [ DllImport( "user32.dll" ) ]
            extern static IntPtr GetClipboardData( uint uFormat );

            public static void GetSomeDib()
                  OpenClipboard( System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle );
                  IntPtr img = GetClipboardData( 8 );

                  // Do Something with img
OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.

just on } missing to close the namespace :)

(fast copy/paste :)

Jayu, did this help ?

Did it solve your prob ?
Jayu ?

Did this help you solve your problem ?

Further assistance ?

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.