C# and handle to Clipboard

hi

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

<snippet>
OpenClipboard(0);
DataObject m_data = new DataObject();
m_data.SetData(DataFormats.Dib,imgCardImage.Image);
Clipboard.SetDataObject(m_data,false);
hDib = GetClipboardData(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.
Jayu_is_hereAsked:
Who is Participating?
 
tgannettsCommented:
Do you have to use the API calls. .Net Framework contains some Clipboard classes.

For example see

http://www.codeproject.com/csharp/clipboard01.asp

Tom.
0
 
Jayu_is_hereAuthor Commented:
Tom,

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.

jayu
0
 
vascovCommented:
Hi,

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
            
                  CloseClipboard();
            }            
}
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
vascovCommented:
just on } missing to close the namespace :)

(fast copy/paste :)

--
vascov
0
 
vascovCommented:
Jayu, did this help ?

Did it solve your prob ?
0
 
vascovCommented:
Jayu ?

Did this help you solve your problem ?

Further assistance ?

Thx
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.