Date sent: Tue, 19 Aug 2008 13:04:36 +0900
From: "Ben Bullock" <[EMAIL PROTECTED]>
To: [email protected]
Subject: Getting the current code page, open with UTF-8
> I am using Win32::OLE to automate Microsoft Word/Excel, and I use utf8
> to communicate with the applications themselves. But when I send a
> UTF-8 string to a routine like
>
> my $filename = "somethinginutf8";
>
> $word->Documents->Open ($filename);
>
> this produces an error. A lot of the files and directories that I need
> to open have Japanese names so it isn't possible for me to avoid the
> problem by just using ASCII. I've found that sending the unencoded
> version of the file name works. However, because I want to write a
> general module which I can release on CPAN, I would prefer to write a
> general solution where the file name was automatically decoded by
> Encode into the correct code page for the user.
>
> So my question is, how can my Perl program find out what the current
> code page of the user is?
use Win32::Registry;
{
my $r;
$::HKEY_LOCAL_MACHINE-
>Open('SYSTEM\CurrentControlSet\Control\NLS\CodePage', $r)
or die "Can't open
HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage:
$^E\n";
$r->GetValue('ACP', $SystemEncoding);
$SystemEncoding = '1252' unless $SystemEncoding;
$SystemEncoding = 'cp' . $SystemEncoding;
}
or if you have the patch that was supposed to become the oficial
version of the Win32::Registry module years ago
$SystemEncoding = 'cp' .
(Win32::Registry::GetValue('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSe
t\Control\NLS\CodePage', 'ACP') || '1252');
Jenda
http://Jenda.Krynicky.cz/#Win32::Registry2
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs