473,320 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Getting Clipboard Handle using GetClipboardData in C#

hi

I am trying to copy an image to a clipboard and then get a
handle to the clipboard using API calls GetClipboardData().

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.

~Roohi
Nov 15 '05 #1
6 5911
Not familiar with GetClipboardData.
Why do you need a handle to it instead of using .NET's
ClipBoard.GetDataObject to retrieve it?

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #2
I need to pass this handle to some other API which accepts
handle to the clipboard as a parameter

Hence I need it

Thanks
-----Original Message-----
Not familiar with GetClipboardData.
Why do you need a handle to it instead of using .NET's
ClipBoard.GetDataObject to retrieve it?

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/.

Nov 15 '05 #3
Hm, maybe Clipboard.SetDataObject() closes the clipboard you opened with
OpenClipboard().
Try moving OpenClipBoard(0); after SetDataObject()
--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #4
I tried doing that, but still the same problem

Roohi
-----Original Message-----
Hm, maybe Clipboard.SetDataObject() closes the clipboard you opened withOpenClipboard().
Try moving OpenClipBoard(0); after SetDataObject()
--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/.

Nov 15 '05 #5
On Wed, 12 Nov 2003 02:25:33 -0800, "Roohi"
<an*************@hotmail.com> wrote:
hi

I am trying to copy an image to a clipboard and then get a
handle to the clipboard using API calls GetClipboardData().

~Roohi


Roohi

Can you modify this to do what you need:

public static bool JCopyFilesToClipboard(string[] strFiles, POINT pt)
{
bool blnReturn = false;
byte[] bData;
DROPFILES df = new DROPFILES();
int intChar, intFile, intDataLen, intPos;
IntPtr ipGlobal = IntPtr.Zero;

// Calculate total data length
intDataLen = 0;
for(intFile = 0; intFile <= strFiles.GetUpperBound(0);
intFile++)
intDataLen += strFiles[intFile].Length + 1;

// Terminating double zero
intDataLen++;

bData = new Byte[intDataLen];
intPos = 0;

// Build null terminated list of files
for(intFile = 0; intFile <= strFiles.GetUpperBound(0);
intFile++)
{
for(intChar = 0; intChar < strFiles[intFile].Length;
intChar++)
{
bData[intPos++] = (byte)strFiles[intFile][intChar];
}
bData[intPos++] = 0;
}
// Terminating double zero
bData[intPos++] = 0;

// Allocate and get pointer to global memory
int intTotalLen = Marshal.SizeOf(df) + intDataLen;
ipGlobal = Marshal.AllocHGlobal(intTotalLen);

if(ipGlobal == IntPtr.Zero)
return false;

// Build DROPFILES structure in global memory.
df.pFiles = Marshal.SizeOf(df);
df.pt = pt;
df.fNC = false;
df.fWide = 0;
Marshal.StructureToPtr(df, ipGlobal, true);
IntPtr ipNew = new IntPtr(ipGlobal.ToInt32() +
Marshal.SizeOf(df));
Marshal.Copy(bData, 0, ipNew, intDataLen);

// Open and empty clipboard
if(!OpenClipboard(IntPtr.Zero))
return false;

EmptyClipboard();

// Copy data to clipboard
blnReturn = (SetClipboardData(CF_HDROP, ipGlobal) !=
IntPtr.Zero);
if(!blnReturn)
Marshal.FreeHGlobal(ipGlobal);

// Clean up
CloseClipboard();
// Clipboard responsible for freeing memory
// Marshal.FreeHGlobal(ipGlobal);

return blnReturn;
}

It's a different file format but the principle is similar.

--
Jeff Gaines Damerham Hampshire UK

Nov 15 '05 #6
On Wed, 12 Nov 2003 02:25:33 -0800, "Roohi"
<an*************@hotmail.com> wrote:
hi

I am trying to copy an image to a clipboard and then get a
handle to the clipboard using API calls GetClipboardData().

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
hDib returned is always 0 where it actually had to return
a handle to the clipboard;

Thanks in Advance.

~Roohi


Roohi

I am not sure now if my earlier post answers your question :-(

I have tried what you are doing - you must call open clipboard before
trying to get the handle to the data. Is the clipboard still open when
you make this call or have you already closed it?

--
Jeff Gaines Damerham Hampshire UK

Nov 15 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: LG | last post by:
Just have a question with regards to the clipboard, and how to read what other applications (Adobe InDesignCS) place in the clipboard. I am currently in the process of creating a booklet from a...
2
by: Gey-Hong Gweon | last post by:
Is there a way to copy a PIL image to windows clipboard (as a dib image or a bitmap, I suppose)? What I would like to accomplish is to do a fast copy and paste of images from my python...
1
by: Nithi Gurusamy | last post by:
Hello everyone: I am new to .NET world. Someone please show me how to use the Clipboard class in an unmanaged code. Assume I have a MFC CString variable strText. How to put the value in...
11
by: Andrey Dzizenko | last post by:
Hi all! Did anyone try the subj? I use extern IsClipboardFormatAvailable and GetClipboardData from user32.dll. IsClipboardFormatAvailable(14) returns true, but GetClipboardData(14)...
15
by: Peter Duniho | last post by:
I'm trying to use .NET and C# to draw a metafile copied to the clipboard by another application (Word 2003 in this case, but it shouldn't matter). I naively thought that I'd be able to use the...
5
by: exhuma.twn | last post by:
As many might know, windows allows to copy an image into the clipboard by pressing the "Print Screen" button on the keyboard. Is it possible to paste such an image from the clipboard into a "Text"...
8
by: active | last post by:
Guess I'm looking for someone who likes to work difficult puzzles. I can't seem to ever retrieve a palette handle from the clipboard. Below is a simple test program that demonstrates the...
5
by: nagar | last post by:
I have a .NET 2.0 application that needs to backup and restore the contents of the clipboard. When I back it up, I use this code: DataObject oldClipboard = Clipboard.GetDataObject();...
23
by: Over | last post by:
Hi it's possible with language C, (Mingw or Djgpp) copying the clipboard of WinXp into file.txt? which function must be use. Thanks
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.