develooper Front page | perl.xs | Postings from September 2017

Help with wchar_t

From:
RAPPAZ Francois via perl-xs
Date:
September 26, 2017 09:41
Subject:
Help with wchar_t
Message ID:
2daa7ea8b7d344d9b9302fb51f053ea8@svw-exmb4.unifr.ch
I'm new to XS, so excuse my basic question

I have a C function that received a pointer to string. The string is scanned and each charater code is placed in a INPUT struct.

void send_string (const wchar_t * str) {
                 printf("send_string : %s L:%i\n", str, wcslen(str));
         ...
                for (p=str ; *p; p++) {
                               ...
                               inp[0].ki.wScan = inp[1].ki.wScan = *p;
                               printf("wScan has %i\n", *p);
                               SendInput(2, inp, sizeof(INPUT));

                }

}

My xs file for this is just

TYPEMAP: <<HERE
const wchar_t * T_WCHAR
INPUT
T_WCHAR
    $var = ($type)SvPV_nolen($arg)
OUTPUT
T_WCHAR
    sv_setpv((SV*)$arg, $var);
HERE

void
send_string(s)
     const wchar_t * s


When I test this send_string function, I see that
                printf("%s", str) is correct
                the value return by wcslen(str) is not constant and is too large, it's herratic and varied from the same string value sent from perl
                the values in wScan are wrong except for the first character

The INPUT and OUTPUT part of the typemap are copied from T_PV.

I have tried more elaborate conversion taken from this thread
http://grokbase.com/t/perl/xs/06bxe1krvk/t-wchar-final
but the code does not  compile.

Thanks for any help.

Fran├žois



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About