Help with wchar_t
[email protected] (RAPPAZ Francois via perl-xs) Tue, 26 Sep 2017 09:33:53 +0000
| Newsgroups | perl.xs |
|---|---|
| Message-ID | <[email protected]> |
--_000_2daa7ea8b7d344d9b9302fb51f053ea8svwexmb4unifrch_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
I'm new to XS, so excuse my basic question
I have a C function that received a pointer to string. The string is scanne=
d 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=3Dstr ; *p; p++) {
...
inp[0].ki.wScan =3D inp[1].ki.wScan =3D *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 =3D ($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 characte=
r
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=E7ois
--_000_2daa7ea8b7d344d9b9302fb51f053ea8svwexmb4unifrch_
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<html xmlns:v=3D"urn:schemas-microsoft-com:vml" xmlns:o=3D"urn:schemas-micr=
osoft-com:office:office" xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns:m=3D"http://schemas.microsoft.com/office/2004/12/omml" xmlns=3D"http:=
//www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Diso-8859-=
1">
<meta name=3D"Generator" content=3D"Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext=3D"edit" spidmax=3D"1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext=3D"edit">
<o:idmap v:ext=3D"edit" data=3D"1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang=3D"FR-CH" link=3D"#0563C1" vlink=3D"#954F72">
<div class=3D"WordSection1">
<p class=3D"MsoNormal"><span lang=3D"EN-GB">I'm new to XS, so excuse my bas=
ic question<o:p></o:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB"><o:p> </o:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB">I have a C function that receiv=
ed a pointer to string. The string is scanned and each charater code is pla=
ced in a INPUT struct.<o:p></o:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB"><o:p> </o:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB">void send_string (const wchar_t=
* str) { <o:p>
</o:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB"> &=
nbsp; printf(&q=
uot;send_string : %s L:%i\n", str, wcslen(str));<o:p></o:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB"> &=
nbsp; ... <o:p></o:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB"> &=
nbsp; for (p=3Dstr ; =
*p; p++) {
<o:p></o:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB"> &=
nbsp; &nbs=
p; =
...<o:p></o:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB"> &=
nbsp; &nbs=
p; =
inp[0].ki.wScan =3D inp[1].ki.wScan =3D *p;<o:p></o:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB"> &=
nbsp; &nbs=
p; =
printf("wScan has %i\n", *p);<o:p></o:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB"> &=
nbsp; &nbs=
p; =
SendInput(2, inp, sizeof(INPUT));<o:p></o:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB"><o:p> </o:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB"> &=
nbsp; } &n=
bsp; <o:p></o:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB"><o:p> </o:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB">}<o:p></o:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB"><o:p> </o:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB">My xs file for this is just<o:p=
></o:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB"><o:p> </o:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB">TYPEMAP: <<HERE<o:p></o:p=
></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB">const wchar_t * T_WCHAR<o:p></o=
:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB">INPUT<o:p></o:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB">T_WCHAR<o:p></o:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB"> $var =3D ($t=
ype)SvPV_nolen($arg)<o:p></o:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB">OUTPUT<o:p></o:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB">T_WCHAR<o:p></o:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB"> sv_setpv((SV=
*)$arg, $var);<o:p></o:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB">HERE<o:p></o:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB"><o:p> </o:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB">void<o:p></o:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB">send_string(s)<o:p></o:p></span=
></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB"> const =
wchar_t * s<o:p></o:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB"><o:p> </o:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB"><o:p> </o:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB">When I test this send_string fu=
nction, I see that
<o:p></o:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB"> &=
nbsp; printf("%s=
", str) is correct<o:p></o:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB"> &=
nbsp; the value retur=
n by wcslen(str) is not constant and is too large, it’s herratic and =
varied from the same string value sent from perl<o:p></o:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB"> &=
nbsp; the values in w=
Scan are wrong except for the first character<o:p></o:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB"><o:p> </o:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB">The INPUT and OUTPUT part of th=
e typemap are copied from T_PV.
<o:p></o:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB"><o:p> </o:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB">I have tried more elaborate con=
version taken from this thread<o:p></o:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB">http://grokbase.com/t/perl/xs/0=
6bxe1krvk/t-wchar-final<o:p></o:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB">but the code does not com=
pile.<o:p></o:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-GB"><o:p> </o:p></span></p>
<p class=3D"MsoNormal">Thanks for any help.<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal">Fran=E7ois<o:p></o:p></p>
</div>
</body>
</html>
--_000_2daa7ea8b7d344d9b9302fb51f053ea8svwexmb4unifrch_--