in reply to Win32::API and CreateProcessWithLogonW

Update: Corrected UTF8LE to UTF-16LE per tye's post below.

The problem is that your are importing the wide (W) api, CreateProcessWithLogonW(), and attempting to pass it ascii character strings. You will need to promote these to UTF-16LE.

Google does turn a handful of references to an A variant, CreateProcessWithLogonA(), but none of them are at an MS site, or anywhere that looks authoratative. I also consulted my 'big list of exports', and no A variant is exported from any of the DLLs on my system. Of those that I've catalogued--I may still have missed some.

I can never remember the official invocations required to convert/promote an ascii string to utf-16le, and you can supersearch as well as I can. "UTF-16LE" would probably be a good search term. From memory, I believe ikegami &| Corion have posted definitive information on this subject, which might serve to speed your search.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^2: Win32::API and CreateProcessWithLogonW
by tye (Sage) on Jan 30, 2007 at 06:50 UTC

    I convert between UTF-16LE (not "UTF8LE" as you wrote) and ASCII or UTF-8 using pack rather simply:

    $utf16= pack "S*", unpack( "C*", $ascii ), 0; $utf16= pack "S*", unpack( "U*", $utf8 ), 0; $ascii= pack "C*", unpack( "S*", $utf16 ); $ascii =~ s/\0$//; $utf8 = pack "U*", unpack( "S*", $utf16 ); $utf8 =~ s/\0$//;

    but note that this doesn't handle extra large Unicode code points (which Windows doesn't handle by default either but can be configured to support at least partially).

    To feel less hackish, one would likely use the Encode module, which can probably also handle the characters in the Windows-1252 extensions to Latin-1.

    - tye        

      I have a couple of similar routines I use for myself, but I'm reluctant to recommend to others, because of the ire they are likely to draw:

      sub A2W{ pack 'S*', unpack 'C*', $_[0] } sub W2A{ pack 'C*', unpack 'S*', $_[0] }

      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        I only see two problems. 1) They don't handle the few characters that are in Windows-1252 but not Latin-1. 2) They don't handle the trailing "\0\0" that is needed on the end of wide strings. (1) certainly hasn't bothered me enough to jump through other hoops very often. (2) can be a real problem in some situations and no problem at all in others.

        Oh, and problem (1) that I also mentioned regarding my versions isn't actually a problem for the UTF-18LE / UTF-8 versions; it is just a problem with "ASCII" versions (which really convert to/from Latin-1), now that I think of it.

        - tye