in reply to Win32 mounting Unicode share
Looking at the source code reveals that, under the hood of Win32::NetResource::AddConnection(), the WNetAddConnection2A Win32 function is being used. This is the ANSI version of the two available WNetAddConnection2 functions — the other version, WNetAddConnection2W, is for Unicode.
Normally, the ANSI versions simply handle / pass through data as a byte string without any special interpretation, so it should probably work if you encode the share name appropriately.
If I'm understanding you correctly, the required CIFS encoding in this case is \x30 \x42, so you could try
my $sharename = Encode::encode("UTF-16BE", $sharename_utf8);
and then use the encoded binary string $sharename in the AddConnection() call. Or, in case that should turn out to be the wrong byte order, try "UTF-16LE". ($sharename_utf8 is the name as a Perl character string, as it would be returned from $sharename_utf8 = "...\x{3042}...".)
If all else fails, you might also try patching Win32::NetResource to use the "wide API" call WNetAddConnection2W, but that would mean having to rebuild the module... My guess would be that - in this particular case - this would neither be necessary, nor provide any particular benefit. HTH.
___
BTW, you can always easily get a hexdump of a string like this:
sub hexdump { print join(" ", unpack("(H2)*", shift)), "\n"; } use Encode; my $sharename_utf8 = "\x{3042}"; my $sharename = encode("UTF-16BE", $sharename_utf8); hexdump($sharename_utf8); # e3 81 82 hexdump($sharename); # 30 42
Update: fixed U --> W in wide-API function name WNetAddConnection2W — thanks monarch!
|
|---|