Solved

C# and handle to Clipboard

Posted on 2003-11-11
8
2,405 Views
Last Modified: 2007-12-19
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.
0
Comment
Question by:Jayu_is_here
  • 4
8 Comments
 
LVL 5

Accepted Solution

by:
tgannetts earned 75 total points
ID: 9721680
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
 

Author Comment

by:Jayu_is_here
ID: 9728186
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
 
LVL 12

Assisted Solution

by:vascov
vascov earned 75 total points
ID: 9796865
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 12

Expert Comment

by:vascov
ID: 9797590
just on } missing to close the namespace :)

(fast copy/paste :)

--
vascov
0
 
LVL 12

Expert Comment

by:vascov
ID: 9813003
Jayu, did this help ?

Did it solve your prob ?
0
 
LVL 12

Expert Comment

by:vascov
ID: 9859079
Jayu ?

Did this help you solve your problem ?

Further assistance ?

Thx
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now