Jump to page: 1 2
Thread overview
how to get the local?
Jun 01, 2011
Lloyd Dupont
Jun 01, 2011
Lloyd Dupont
Jun 01, 2011
Andrej Mitrovic
Jun 01, 2011
Lloyd Dupont
Jun 01, 2011
Andrej Mitrovic
Jun 01, 2011
Andrej Mitrovic
Jun 01, 2011
Lloyd Dupont
Jun 01, 2011
Andrej Mitrovic
Jun 02, 2011
Nick Sabalausky
Jun 02, 2011
Andrew Wiley
Jun 02, 2011
Lloyd Dupont
Jun 01, 2011
Lloyd Dupont
Jun 01, 2011
Don
June 01, 2011
I'm on a windows PC in Australia
I'd like to get the string "en-AU" and "en" from Windows....
How do I do that please?
June 01, 2011
I tried to add that to my D file
===
public import std.c.windows.windows;

extern(Windows)
{
   int GetUserDefaultLocaleName(LPWSTR lpLocaleName, int cchLocaleName);
}
===
and compile and link to kernel32.lib

But I got the following compile error:
Error    1    Error 42: Symbol Undefined _GetUserDefaultLocaleName@8 C:\Dev\DTest\DTest1\Dexperiment\

Any clues?


"Lloyd Dupont"  wrote in message news:is5gm7$1a8u$1@digitalmars.com...

I'm on a windows PC in Australia
I'd like to get the string "en-AU" and "en" from Windows....
How do I do that please? 

June 01, 2011
>From what I can tell you're using the wide version, so try prototyping
it as GetUserDefaultLocaleNameW <- note the W

Otherwise you should really get http://dsource.org/projects/bindings/wiki/WindowsApi , which has prototypes for many windows functions. You just have to build and use it with --version=Unicode if you want GetUserDefaultLocaleName to alias itself to GetUserDefaultLocaleNameW.
June 01, 2011
On Wed, 01 Jun 2011 10:31:45 -0400, Lloyd Dupont <ld-REMOVE@galador.net> wrote:

> I tried to add that to my D file
> ===
> public import std.c.windows.windows;
>
> extern(Windows)
> {
>     int GetUserDefaultLocaleName(LPWSTR lpLocaleName, int cchLocaleName);
> }
> ===
> and compile and link to kernel32.lib
>
> But I got the following compile error:
> Error    1    Error 42: Symbol Undefined _GetUserDefaultLocaleName@8 C:\Dev\DTest\DTest1\Dexperiment\
>
> Any clues?

Typically, windows functions come in two varieties, the A and the W version.  This is hidden by a macro in C, so all you ever call is GetUserDefaultLocaleName (and that's how it is in the docs even).  But in D, which does not have a pre-processor, you must add the A (ascii) or W (wide) to the function name.  Try:

extern(Windows)
{
    int GetUserDefaultLocaleNameW(LPWSTR lpLocaleName, int cchLocaleName);
}

-Steve
June 01, 2011
Lloyd Dupont wrote:
> I tried to add that to my D file
> ===
> public import std.c.windows.windows;
> 
> extern(Windows)
> {
>    int GetUserDefaultLocaleName(LPWSTR lpLocaleName, int cchLocaleName);
> }
> ===
Try:
extern(Windows)
{
   int GetUserDefaultLocaleNameW(LPWSTR lpLocaleName, int cchLocaleName);
}

> and compile and link to kernel32.lib
> 
> But I got the following compile error:
> Error    1    Error 42: Symbol Undefined _GetUserDefaultLocaleName@8 C:\Dev\DTest\DTest1\Dexperiment\
> 
> Any clues?
> 
> 
> "Lloyd Dupont"  wrote in message news:is5gm7$1a8u$1@digitalmars.com...
> 
> I'm on a windows PC in Australia
> I'd like to get the string "en-AU" and "en" from Windows....
> How do I do that please?
June 01, 2011
Thanks for the link hey! :)
Otherwise I still get the same linking error with the W :(


"Andrej Mitrovic"  wrote in message news:mailman.518.1306939098.14074.digitalmars-d-learn@puremagic.com...

>From what I can tell you're using the wide version, so try prototyping
it as GetUserDefaultLocaleNameW <- note the W

Otherwise you should really get
http://dsource.org/projects/bindings/wiki/WindowsApi , which has
prototypes for many windows functions. You just have to build and use
it with --version=Unicode if you want GetUserDefaultLocaleName to
alias itself to GetUserDefaultLocaleNameW. 

June 01, 2011
On Wed, 01 Jun 2011 16:13:44 -0400, Lloyd Dupont <ld-REMOVE@galador.net> wrote:

> Thanks for the link hey! :)
> Otherwise I still get the same linking error with the W :(

It looks like that particular function does not have the A and W versions.

See this page:

http://msdn.microsoft.com/en-us/library/dd318136%28v=vs.85%29.aspx

And see this for an example of something that comes in W and A variety:

http://msdn.microsoft.com/en-us/library/dd317759%28v=VS.85%29.aspx

Note at the bottom the "Unicode and ANSI names" part.

Here is my new theory -- note that the function is only defined on Vista or later.  DMD does not use the same object format as Windows (i.e. Visual C++), so all libraries have to be "converted" to a form that dmd can link with.  Most of the relevant Windows lib files are already pre-converted and included in the dmd distribution under windows/lib.  I'd bet that the version of kernel32.lib that was used to generate this file is an XP version, which would not contain this function.

I'd recommend investigating how to replace that kernel32.lib with the Vista (or later) version (I'm sure someone will tell you here ;) or try using the predecessor function, which should be universally compatible (See the above noted documentation).

-Steve

>
>
> "Andrej Mitrovic"  wrote in message news:mailman.518.1306939098.14074.digitalmars-d-learn@puremagic.com...
>
>> From what I can tell you're using the wide version, so try prototyping
> it as GetUserDefaultLocaleNameW <- note the W
>
> Otherwise you should really get
> http://dsource.org/projects/bindings/wiki/WindowsApi , which has
> prototypes for many windows functions. You just have to build and use
> it with --version=Unicode if you want GetUserDefaultLocaleName to
> alias itself to GetUserDefaultLocaleNameW.
June 01, 2011
>From my understanding of this page
http://msdn.microsoft.com/en-us/library/dd318136%28v=vs.85%29.aspx :

"Note  The application should call this function in preference to GetUserDefaultLCID if designed to run only on Windows Vista and later."

It's not in kernel32.lib distributed with DMD. You would have to create an OMF import lib by calling implib /system kernel32.dll (your own kernel32.dll) if you're actually using Vista or a newer OS and then linking with that. But you can say goodbye to supporting Windows older than Vista.

OTOH GetUserDefaultLCID /is/ in the kernel32.lib distributed with DMD. So why not use that?
June 01, 2011
I beat you Steven!!

:P
June 01, 2011
On Wed, 01 Jun 2011 16:38:05 -0400, Andrej Mitrovic <andrej.mitrovich@gmail.com> wrote:

> I beat you Steven!!
>
> :P

According to my newsreader and webnews, I beat you by 2 seconds:

http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.learn&article_id=27286

From	Andrej Mitrovic <andrej.mitrovich@gmail.com>
Date	Wed, 1 Jun 2011 22:34:15 +0200

http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.learn&article_id=27285


From	Steven Schveighoffer <schveiguy@yahoo.com>
Date	Wed, 01 Jun 2011 16:34:13 -0400

Note also the ordering of the article ids ;)

so THERE!

-Steve
« First   ‹ Prev
1 2