I'm working on a program that interacts with another Windows program (an editor). It selects all of the text (possibly unicode) under one tab, copies it to the clipboard, retrieves it from the clipboard, adds some markup, then pastes the marked-up text back to the other program under a new tab via the clipboard. At least, that's what's supposed to happen. Here's a skeletal version of the
Markup routine that simply echoes back to the clipboard the text that it reads. The
prints are there to monitor the text conversions:
sub Markup {
$textarea = (grep {IsWindowVisible($_)} (FindWindowLike($ide, unde
+f, qr/Edit/, undef, undef)))[0];
SetForegroundWindow($textarea);
SendKeys('^a^c{HOME}');
my $source = $clip->GetAs(CF_UNICODETEXT);
print map {sprintf("%2.2X ", ord($_))} (split //, $source); print
+"\n\n";
$source = Encode::decode("UTF16-LE", $source);
print map {sprintf("%2.2X ", ord($_))} (split //, $source); print
+"\n\n";
$source = Encode::encode("UTF16-LE", $source);
print map {sprintf("%2.2X ", ord($_))} (split //, $source); print
+"\n\n";
$clip->Set($source);
SendKeys('^n^v')
}
According to the routine's output, the conversions are done correctly. The problem occurs when trying to write the text back to the clipboard. It appears to be treated as a zero-terminated byte string, rather than
UTF16-LE-encoded text. What appears to be needed is a
SetAs method, but there is none. Is there any way I can signal that the text being written to the clipboard is supposed to be
UTF16-LE and not ASCII?
Thanks,
-Phil