I'm trying to call the Win32 API function GetSystemDefaultLangID() via Perl's Win32::API module, but I can't get it to work.

Here's the program that I thought would give me the answer:

use strict; use warnings; use Win32::API; Win32::API->Import('kernel32.dll', 'LANGID 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"; }

However, when I run this it just outputs:

Returned <undef>

The function itself works fine from a simple C program:

#include <stdio.h> #include <windows.h> #include <winnls.h> void main(void) { printf("Lang ID = 0x%04X\n", GetSystemDefaultLangID()); }

and similar Perl Win32::API programs involving other Win32 API functions also work fine, e.g.

use strict; use warnings; use Win32::API; Win32::API->Import('kernel32.dll', 'DWORD GetCurrentProcessId()') or die "Can't import GetCurrentProcessId: $^E\n"; my $procid = GetCurrentProcessId(); if (defined $procid) { print "Returned '$procid'\n"; } else { print "Returned <undef>\n"; }

Where can I have gone wrong with something so simple, or is this a bug in Win32::API?

- Steve


In reply to How to call GetSystemDefaultLangID() with Win32::API by shay

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.