Solved

C# and handle to Clipboard

Posted on 2003-11-11
8
2,457 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
Independent Software Vendors: 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Suggested Solutions

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 article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

738 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