more useful options | |
PerlMonks |
Where is my string going in Win32::API ?by John M. Dlugosz (Monsignor) |
on Jul 03, 2001 at 06:11 UTC ( [id://93396]=perlquestion: print w/replies, xml ) | Need Help?? |
John M. Dlugosz has asked for the wisdom of the Perl Monks concerning the following question:
Puzzle me this, Oh Wise Monks: The following piece of code gets, changes one character, and sets a window's label using the Wide system calls and UTF16-LE strings.
The tr// at the end is to make it print out usefully on an 8-bit console. I can see where the 0's are and that all the chars are properly LE with the ASCII code in the first byte and 0 in the second, and my new 16-bit character is properly aligned. If I un-comment one of the substr lines, the new character does indeed appear in the window, but the string is truncated! How much is truncated seems to vary with the exact string! Maybe 5 chars in one case. That's even if the substr took place at the very first position. When dumping my string via print, I can see that it is put together correctly, every byte where it belongs. So I'm wondering what might be making the system call quit early? Are strings discontiguous in memory and this is now two fragments? If I Get the text out again, I see that bytes have actually been deleted, and stuff after it moved up, not just truncated by getting the length wrong. The Win32 calls take nul-terminated input, so the Set stops when it sees \0\0 in the buffer. Yet the value of $s is unaltered after I call Set, but Get again implies that Set deleted a few bytes before passing it along to the actual OS call. Is this strange or what? I'm totally mystified. Full program follows. —John
Back to
Seekers of Perl Wisdom
|
|