Solved

C# and handle to Clipboard

Posted on 2003-11-11
8
2,469 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

696 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