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!


In reply to Re: Win32 mounting Unicode share by almut
in thread Win32 mounting Unicode share by ririparis

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.