Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Clipboard GetData with UTF-8 EURO Sign produces wrong output

12 views
Skip to first unread message

Pierre Arnaud

unread,
Apr 22, 2006, 10:12:05 AM4/22/06
to
Hi,

I am currently trying to read the contents of the Clipboard from
a WinForms application. I am specifically interested in the "HTML
Format" format which gets stored into the clipboard when I copy
a fragment of text containing the EURO character (Unicode 20AC)
in Word.

When calling DataObject.GetData ("HTML Format") I get a string as
result. The string does not, however, properly represent the data
stored in the clipboard.

The raw data (as seen with ClipSpy for instance) contains the
following UTF-8 byte stream :

... E2 82 AC ...

This should decode to 20AC, since :

E2 = 1110'0010 -- 1110'zzzz
82 = 1000'0010 -- 10yy'yyyy
AC = 1010'1100 -- 10xx'xxxx

This is a 3-byte encoding sequence mapping to zzzz'yyyy'yyxx'xxxx,
which is 0010'0000'1010'1100 = 20AC = EURO Currency Symbol.

But the string returned by GetData is faulty at that point. It
contains the following, incorrectly decoded, characters :

0x00e2 0x201a

There seems to be a bug in the .NET Clipboard code implementation.

You can make my application (available at www.creativedocs.net)
crash if you copy a EURO symbol (with my keyboard layout, AltGr-E)
in Word and paste it to any text line in the application.

I'd be glad to have a work-around for this issue !

Pierre


Jeffrey Tan[MSFT]

unread,
Apr 24, 2006, 1:44:16 AM4/24/06
to
Hi Pierre ,

Thanks for your post!

It seems that this issue has been reported by other customer, please refer
to the link below:
http://lab.msdn.microsoft.com/ProductFeedback/viewFeedback.aspx?feedbackid=7
c8c48a9-d8c1-482c-b81d-b1335f12e75d

You may check if this is the same issue as you. Based on the link, it seems
that we can use System.Runtime.InteropServices.ComTypes.IDataObject to
workaround this issue.

Note: this bug request is currently being processed by the product team, we
may wait for the further feedback.

Hope this helps!

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Pierre Arnaud

unread,
Apr 24, 2006, 8:51:53 AM4/24/06
to
Hi Jeffrey,

> It seems that this issue has been reported by other customer, please
> refer to the link below:
> http://lab.msdn.microsoft.com/ProductFeedback/viewFeedback.aspx?feedbackid=
> 7c8c48a9-d8c1-482c-b81d-b1335f12e75d
>
> You may check if this is the same issue as you.

Indeed, the symptoms are the very same as those I am suffering from. It
is always good to know that you are not alone in the dark ;-)

> Based on the link, it
> seems that we can use
> System.Runtime.InteropServices.ComTypes.IDataObject to workaround
> this issue.

No idea what this means. I've found no ComTypes.IDataObject while
browsing the .NET 2.0 system DLLs with Reflector.

> Note: this bug request is currently being processed by the product
> team, we may wait for the further feedback.

Let's hope that this we won't have to wait too long on this issue. For
me (micro ISV) this is a really annoying issue, preventing me from using
the clipboard to copy/paste HTML data to my application.

> Hope this helps!

Not really. Is there any possibility to escalate this bug so that I can
get a fix/workaround soon? I am a Microsoft Certified Partner/ISV, maybe
there are some resources available for such cases?

Thanks

Pierre


Jeffrey Tan[MSFT]

unread,
Apr 25, 2006, 2:18:47 AM4/25/06
to
Hi Pierre,

Thanks for your feedback.

IDataObject interface exists in .Net FCL 2.0. You can find it in MSDN.

However, regarding the customer's workaround, I can not understand what
does "with the help of interop methods using formatetc and stgmedium,
globalsize etc" mean, so I can not provide further information for it.

Because the product team is still working on this issue, before they
confirm this as a bug, we can not request a hotfix first. Also, I do not
think escalate will help you anymore. We'd better wait for the Microsft
developer confirm first, then you may request the hotfix regarding this
bug.

Thanks for the understanding.

Pierre Arnaud

unread,
Apr 26, 2006, 2:20:14 AM4/26/06
to
"Jeffrey Tan[MSFT]" wrote:

> IDataObject interface exists in .Net FCL 2.0. You can find it in MSDN.

Indeed, but this seems not to be what the customer was talking about.
Using the DataObject (or IDataObject) produces the exact same mis-
behavior.

> However, regarding the customer's workaround, I can not understand
> what does "with the help of interop methods using formatetc and
> stgmedium, globalsize etc" mean, so I can not provide further
> information for it.

OK. Thanks anyway.

> Because the product team is still working on this issue, before they
> confirm this as a bug, we can not request a hotfix first. Also, I do
> not think escalate will help you anymore. We'd better wait for the
> Microsft developer confirm first, then you may request the hotfix
> regarding this bug.

I wonder what "working on the issue" might mean, as reproducing it is
very easy with the code provided by the customer. It should not be a
problem to classify it as a *bug*.

So, let's hope things get sorted out soon.

Pierre


Jeffrey Tan[MSFT]

unread,
Apr 26, 2006, 2:42:47 AM4/26/06
to
Hi Pierre ,

I think it is based on the product team's schedule time-line. There may be
many bug requests pending for approve, and the developers have to process
them one-by-one. Thanks for your understanding.

FullMetal

unread,
Apr 27, 2006, 8:29:25 AM4/27/06
to
Hello, I'm the original bug submitter.

I'm somewhat dismayed to see that the bug status was not updated for so many months. This is a serious issue and I couldn't believe that nobody else was affected by it.

Sometimes I check on the feedback page for some change and today I found Petrus's comment.

Now I'm glad that I'm not "alone in the dark" too!

I will update the page with some new insights of these months and thanks to Pierre Arnaud's input I'm changing the example application to include the Euro symbol issue.

Most of all, yes, I elaborated a solution that works well for me, but since I'm not much of an expert in p/invoke I would like to have a comment on its correctness by some real expert about the GlobalLock and GlobalUnlock section before posting it on MS's official site. I'll put it on a blog and wait for comments and if everything will be ok, publish it here and on the feedback page as a workaround.

I'll post shortly an update on this thread.

Anyone can vote on this issue and make MS developers more aware of the DataObject html bug.

The feedback page: http://tinyurl.com/r7yd2

JX

---
Posted via www.DotNetSlackers.com

Pierre Arnaud

unread,
Apr 28, 2006, 1:48:22 AM4/28/06
to
Hi FullMetal,

FullMetal wrote:
> Hello, I'm the original bug submitter.
>
> I'm somewhat dismayed to see that the bug status was not updated for
> so many months. This is a serious issue and I couldn't believe that
> nobody else was affected by it.
>
> Sometimes I check on the feedback page for some change and today I
> found Petrus's comment.
>
> Now I'm glad that I'm not "alone in the dark" too!
>
> I will update the page with some new insights of these months and
> thanks to Pierre Arnaud's input I'm changing the example application
> to include the Euro symbol issue.
>
> Most of all, yes, I elaborated a solution that works well for me, but
> since I'm not much of an expert in p/invoke I would like to have a
> comment on its correctness by some real expert about the GlobalLock
> and GlobalUnlock section before posting it on MS's official site.
> I'll put it on a blog and wait for comments and if everything will be
> ok, publish it here and on the feedback page as a workaround.

Would you mind sharing your blog's address ?

If you've been waiting for months on this issue, I fear nothing will
happen in the following days/weeks, so I'll have to walk the P/Invoke
path too. I'd be glad to test your code and give you some feed-back.

Pierre

FullMetal

unread,
May 2, 2006, 6:42:23 AM5/2/06
to
Hello,

I wrote a brief article and included a demo application
with my workaround for this problem.

You can find it at

http://bakamachine.blogspot.com

specifically at

http://bakamachine.blogspot.com/2006/05/workarond-for-dataobject-html.html

Let me know if it works.

Pierre Arnaud

unread,
May 3, 2006, 3:46:29 PM5/3/06
to
FullMetal wrote:

> I wrote a brief article and included a demo application
> with my workaround for this problem.
>
> You can find it at
>
> http://bakamachine.blogspot.com
>
> specifically at
>
> http://bakamachine.blogspot.com/2006/05/workarond-for-dataobject-html.html
>
> Let me know if it works.

Wonderful work. You dig rather deep into .NET with all your work. I was
able to solve my problem by simply P/Invoking into a tiny Win32 DLL which
contains following code, as I did not have to rely on the IDataObject :

#define EXPORT extern "C" __declspec( dllexport )

static void* clipboardData = NULL;
static int clipboardSize = 0;
static int clipboardHtmlFormat = RegisterClipboardFormat(L"HTML Format");


EXPORT int ReadHtmlFromClipboard(HWND mainWindow)
{
if (clipboardData != NULL)
{
free (clipboardData);
clipboardData = NULL;
}

clipboardData = NULL;
clipboardSize = 0;

if (!IsClipboardFormatAvailable (clipboardHtmlFormat))
{
return 0;
}
if (OpenClipboard(mainWindow))
{
HGLOBAL globalLockHandle = GetClipboardData(clipboardHtmlFormat);

if (globalLockHandle != NULL)
{
BYTE* pData = (BYTE*)GlobalLock(globalLockHandle);

if (pData != NULL)
{
clipboardSize = GlobalSize(globalLockHandle);
clipboardData = malloc(clipboardSize);

if (clipboardData != NULL)
{
memcpy(clipboardData, pData, clipboardSize);
}
else
{
clipboardSize = 0;
}

GlobalUnlock(globalLockHandle);
}
}

CloseClipboard();
}

return clipboardSize;
}


EXPORT void ReadClipboardData(BYTE* buffer, int size)
{
if (size > clipboardSize)
{
size = clipboardSize;
}

if (clipboardData != NULL)
{
memcpy(buffer, clipboardData, size);
}
}


EXPORT void FreeClipboardData()
{
if (clipboardData != NULL)
{
free (clipboardData);

clipboardData = NULL;
clipboardSize = 0;
}
}


FullMetal

unread,
May 5, 2006, 1:43:31 PM5/5/06
to
Hi Pierre,
thank you very much for your praise, great work from your part too, I hope we helped all the other people affected by this problem.

SweatingEgg;;

unread,
May 8, 2006, 6:09:55 AM5/8/06
to
Hello, Pierre And FullMetal

I'm glad to meet you guys.

I was suffered from the same bug, and reported it to Korea MS
service center. They said it is a bug.
Also often I have been checking the feedback center and voted 5 stars
for this problem to be prioritized.

My workaound is like the one FullMetal posted.

http://groups.google.co.kr/group/microsoft.public.dotnet.framework/browse_thread/thread/c046e06be06d68b5/f9817ba727942729?lnk=st&q=.net+html+clipboard+format+utf-8+korean&rnum=1&hl=ko#f9817ba727942729

It just applies to clipboard data, and not solve problem for
drag-and-drop data.

I'm waiting for .NET engineer solve this problem.

If you have any news or question, please e-mail to "in...@clixon.co.kr".

SweatingEgg;;

FullMetal

unread,
May 15, 2006, 5:15:19 AM5/15/06
to
Hello SweatingEgg;;

It's great to see that more people resolved this problem, I think now we are spanning three continents, as I'm from Europe.

Keep up the good work!
---
Posted via www.DotNetSlackers.com

0 new messages