Clipboard GetData with UTF-8 EURO Sign produces wrong output

P

Pierre Arnaud

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
 
J

Jeffrey Tan[MSFT]

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.
 
P

Pierre Arnaud

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
 
J

Jeffrey Tan[MSFT]

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.

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.
 
P

Pierre Arnaud

Jeffrey Tan said:
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
 
J

Jeffrey Tan[MSFT]

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.

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.
 
F

FullMetal

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
 
P

Pierre Arnaud

Hi FullMetal,
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
 
P

Pierre Arnaud

FullMetal said:
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;
}
}
 
F

FullMetal

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.

JX
 
S

SweatingEgg;;

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/mi...at+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 "(e-mail address removed)".

SweatingEgg;;
 
F

FullMetal

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top