Win32::API's "P" will copy the "string" up to the first '\0'. It sounds like you have a (what Microsoft calls) "UNICODE" string (16-bit characters), so you've got something like "s\0t\0r\0i\0n\0g\0\0\0". So you can't use Win32::API's "P" since then only "s\0" gets copied.

But if that is the case, then you are probably supposed to pass in 16-bit-character strings as well. Which means something similar to (I can't really test this since I don't have your *.dll):

#!/usr/bin/perl -w use strict; use Win32::API; my $PGetAddress = Win32::API->new( 'IBKGetAddress2.dll', 'GetAddress', 'PP', 'N' ) or die "Can't import API : $!\n"; my $Address = pack "S*", unpack("C*","419 w 154"), 0; my $ZipCode = pack "S*", unpack("C*","10032"), 0; my $return = $PGetAddress->Call( $Address, $ZipCode ) or die "Can't run API: $! ($^E)\n"; my $string = pack "C*", unpack "S*", unpack "P2000", pack "L", $return +; $string =~ s/\0.*//s; print "Output: ($string)\n";

If you've got a variable-length output string, then things get really ugly.

But this is all just guessing.

Oh, and by way of explanation, the first two strings of pack/unpack convert 8-bit-character strings into 16-bit-character strings. The last string of pack/unpack goes like this:

Make what looks like a C struct containing the pointer that was returned:
    pack "L", $return;
Copy into a Perl string the 2000 bytes which that pointer points to:
    unpack "P2000",
Get the list of numbers from treating each pair of bytes (16 bits) as a number:
    unpack "S*",
Build a string from those numbers:
    my $string = pack "C*",
Remove the terminating '\0' and anything after it:
    $string =~ s/\0.*//s;

- tye        


In reply to Re: Win32::API returns 1 character when reading a VB DLL ("UNICODE") by tye
in thread Win32::API returns 1 character when reading a VB DLL by rpnoble

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.