Solved

C# and handle to Clipboard

Posted on 2003-11-11
8
2,448 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

756 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