Clipboard Issue
-
Not so subtle. This code is an extremely simple form of the code which caused the bug. The code works without any issues in most circumstances.
void CopyToClipboard(CString str)
{
HGLOBAL hglb = GlobalAlloc(GMEM_MOVEABLE,
(str.Length() + 1) * sizeof(TCHAR));
if (hglb == NULL)
return;LPTSTR lptstr = GlobalLock(hglb);
memcpy(lptstr, static_cast<LPCTSTR>(str),
(str.Length() + 1) * sizeof(TCHAR));GlobalUnlock(hglb);
// Place the handle on the clipboard.
SetClipboardData(CF_TEXT, hglb);
}What broke the code?
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan
-
Not so subtle. This code is an extremely simple form of the code which caused the bug. The code works without any issues in most circumstances.
void CopyToClipboard(CString str)
{
HGLOBAL hglb = GlobalAlloc(GMEM_MOVEABLE,
(str.Length() + 1) * sizeof(TCHAR));
if (hglb == NULL)
return;LPTSTR lptstr = GlobalLock(hglb);
memcpy(lptstr, static_cast<LPCTSTR>(str),
(str.Length() + 1) * sizeof(TCHAR));GlobalUnlock(hglb);
// Place the handle on the clipboard.
SetClipboardData(CF_TEXT, hglb);
}What broke the code?
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan
Rama Krishna Vavilala wrote:
What broke the code?
A Unicode build?
CF_TEXT
is ANSI text only.Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
-
Rama Krishna Vavilala wrote:
What broke the code?
A Unicode build?
CF_TEXT
is ANSI text only.Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
Exactly. It was embarrassing when I found that in a beta demo.
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan
-
Exactly. It was embarrassing when I found that in a beta demo.
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan
Rama Krishna Vavilala wrote:
It was embarrassing when I found that in a beta demo.
Don't be too embarrassed. I'm sure many people have done that before :)
Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
-
Rama Krishna Vavilala wrote:
What broke the code?
A Unicode build?
CF_TEXT
is ANSI text only.Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
-
I looked at that too, but I was under the impression that UNICODE apps would automagically translate CF_TEXT to CF_UNICODETEXT. Maybe that is only when reading the clipboard:doh:
If that happened automatically there will be lot of problems. For example cutting and pasting between an Unicode app and a ANSI app. So you have to either implement CF_TEXT only or both CF_TEXT and CF_UNICODETEXT
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan
-
I looked at that too, but I was under the impression that UNICODE apps would automagically translate CF_TEXT to CF_UNICODETEXT. Maybe that is only when reading the clipboard:doh:
PJ Arends wrote:
I looked at that too, but I was under the impression that UNICODE apps would automagically translate CF_TEXT to CF_UNICODETEXT.
Nope. I have set up a macro that #defines another constant to be one or the other depending on whether I'm compiling for Unicode, but it's not done automatically. I can't remember about reading, but I think you still have to specify it. Remember that you can copy both to the clipboard, so both are available at any time.
Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"