Subject: | Problem with "SHORT" return types? |
Hi,
I have a problem using Win32::API to call a Win32 API function that returns a LANGID (which I believe, from the MS header files, is a WORD, i.e. a USHORT).
It seems that if I specify LANGID (or WORD) in the prototype then the function returns the undefined value:
#####
use Win32::API;
Win32::API->Import('kernel32.dll', 'WORD GetSystemDefaultLangID()') or
die "Can't import GetSystemDefaultLangID: $^E\n";
my $langid = GetSystemDefaultLangID();
if (defined $langid) {
print "Returned '$langid'\n";
printf "Lang ID: 0x%04X\n", $langid;
}
else {
print "Returned <undef>\n";
}
#####
The above program prints "Returned <undef>", rather than giving the expected output.
In order to make the program work, I have to pretend that the return type is a DWORD and then mask off the high WORD which is otherwise full of garbage and spoils the result:
#####
Win32::API->Import('kernel32.dll', 'DWORD GetSystemDefaultLangID()') or
die "Can't import GetSystemDefaultLangID: $^E\n";
my $langid = GetSystemDefaultLangID() & 0xffff;
#####
Also, I think that the entry in Win32::API::Types' __DATA__ section for LANGID is wrong -- it says 's', meaning a signed short, but I believe it should say 'S', meaning an unsigned short.
This is using Win32-API-0.41 on WinXP/VC++ 6 with perl-5.8.4.