Well after a few days of research here is what I came up with. Thanks for all of your help and pointing me in the right direction. The main point that I learned was to get unicode to work in filenames and paths you need to get platform specific. It would be great if that was not the case. Here is the code that I got working. It is running on Windows XP with Perl 5.8.8 (from Active State). Working script:
#!/usr/bin/perl
use strict;
use Win32API::File qw( :ALL );
use utf8;
use Encode;
#Notice the \0 at the end of the file name. Necessary but I don't kno
+w why.
my $win32_handle = Win32API::File::CreateFileW(Encode::encode("UTF-16L
+E", "C:\\test\\" . "
一棵高树
" . "\\test.txt\0"), FILE_READ_DATA, 0, [], OPEN_EXISTING, 0, []);
my $perl_handle = 0;
#This translates the win32 file handle to a Perl file handle
Win32API::File::OsFHandleOpen($perl_handle, $win32_handle, "r");
print <$perl_handle>;
if ($^E)
{
print "Error: " . $^E
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.