http://qs321.pair.com?node_id=1168660


in reply to How to pass a pointer to an array of 'unsigned char' C data type with Win32::API

my $data_ref = pack ('C*', (0x81 , 0x55, 0x00, 0xE0));

That is close to what you want. It would have worked on a slightly older version of Perl. However, p5p have decided that packing binary structures in Perl should honor Unicode (don't get me started). So you get problematic results:

$ say "0x81, 0x55, 0x00, 0xE0" 129 85 0 224 $ say "unpack 'U0C*', pack 'C*', 0x81, 0x55, 0x00, 0xE0" 194 129 85 0 195 160

You're first and last values, having their 8th bit set, got turned into UTF-8 byte sequences (2 bytes each). You can prepend "U0" to the front of the pack template to avoid such.

- tye