www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - how to get the local?

reply "Lloyd Dupont" <ld-REMOVE galador.net> writes:
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?
Jun 01 2011
next sibling parent reply "Lloyd Dupont" <ld-REMOVE galador.net> writes:
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? 
Jun 01 2011
next sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
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
Jun 01 2011
prev sibling next sibling parent Don <nospam nospam.com> writes:
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);
 }
 ===

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?

Jun 01 2011
prev sibling next sibling parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
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

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.

Jun 01 2011
parent "Lloyd Dupont" <ld-REMOVE galador.net> writes:
Thanks, I'll have a look tonight!

"Steven Schveighoffer"  wrote in message 
news:op.vwezfbqmeav7ka localhost.localdomain...

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

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).
Jun 01 2011
prev sibling next sibling parent reply Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
From my understanding of this page

"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?
Jun 01 2011
parent reply "Nick Sabalausky" <a a.a> writes:
"Andrej Mitrovic" <andrej.mitrovich gmail.com> wrote in message 
news:mailman.521.1306960464.14074.digitalmars-d-learn puremagic.com...
From my understanding of this page

"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?

Lloyd, if the program you're writing is designed to be sold or distributed to the public then I'd highly recommend against doing anything that requires at least Vista. From what I've heard, the adoption rates of Vista and Win7 haven't been very good and about half of the Windows systems out there are still XP and pretty much holding there. A *lot* of Windows users are deliberately sticking with XP, and you'll be loosing a lot of people. Of course, if your software is only designed to be used internally by some company, or just for you own use, etc., then obviously it doesn't matter...
Jun 01 2011
parent "Lloyd Dupont" <ld-REMOVE galador.net> writes:
Yes and no!

On one hand I'm a fervent believer of all things Windows 7! :P

On the other hand my (learning) D project is about writing an installer. 
Which should just work with no unexpected dependencies!
I was telling to myself earlier today too that I should not use this 
function, just in case! :)


"Nick Sabalausky"  wrote in message news:is770e$1a00$1 digitalmars.com...

"Andrej Mitrovic" <andrej.mitrovich gmail.com> wrote in message
news:mailman.521.1306960464.14074.digitalmars-d-learn puremagic.com...
From my understanding of this page


Lloyd, if the program you're writing is designed to be sold or distributed to the public then I'd highly recommend against doing anything that requires at least Vista. From what I've heard, the adoption rates of Vista and Win7 haven't been very good and about half of the Windows systems out there are still XP and pretty much holding there. A *lot* of Windows users are deliberately sticking with XP, and you'll be loosing a lot of people. Of course, if your software is only designed to be used internally by some company, or just for you own use, etc., then obviously it doesn't matter...
Jun 02 2011
prev sibling next sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
I beat you Steven!!

:P
Jun 01 2011
prev sibling next sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
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
Jun 01 2011
prev sibling next sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On 6/1/11, Steven Schveighoffer <schveiguy yahoo.com> wrote:
 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

Well, I'll have to write a formal complaint to Google for making me believe I've won this battle. Tip o' the hat to you, Sir.
Jun 01 2011
prev sibling parent Andrew Wiley <wiley.andrew.j gmail.com> writes:
--0016369fa152cd5f4a04a4b42e84
Content-Type: text/plain; charset=ISO-8859-1

On Thu, Jun 2, 2011 at 12:23 AM, Nick Sabalausky <a a.a> wrote:

 "Andrej Mitrovic" <andrej.mitrovich gmail.com> wrote in message
 news:mailman.521.1306960464.14074.digitalmars-d-learn puremagic.com...
From my understanding of this page

"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?

Lloyd, if the program you're writing is designed to be sold or distributed to the public then I'd highly recommend against doing anything that requires at least Vista. From what I've heard, the adoption rates of Vista and Win7 haven't been very good and about half of the Windows systems out there are still XP and pretty much holding there. A *lot* of Windows users are deliberately sticking with XP, and you'll be loosing a lot of people. Of course, if your software is only designed to be used internally by some company, or just for you own use, etc., then obviously it doesn't matter... Actually, Windows 7 is growing somewhat exponentially and XP is falling,

around 45%. --0016369fa152cd5f4a04a4b42e84 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <div class=3D"gmail_quote">On Thu, Jun 2, 2011 at 12:23 AM, Nick Sabalausky= <span dir=3D"ltr">&lt;a a.a&gt;</span> wrote:<br><blockquote class=3D"gmai= l_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left= :1ex;"> &quot;Andrej Mitrovic&quot; &lt;<a href=3D"mailto:andrej.mitrovich gmail.co= m">andrej.mitrovich gmail.com</a>&gt; wrote in message<br> news:mailman.521.1306960464.14074.digitalmars-d-learn puremagic.com...<br> <div><div></div><div class=3D"h5">&gt; &gt;From my understanding of this pa= ge<br> &gt; <a href=3D"http://msdn.microsoft.com/en-us/library/dd318136%28v=3Dvs.8= 5%29.aspx" target=3D"_blank">http://msdn.microsoft.com/en-us/library/dd3181= 36%28v=3Dvs.85%29.aspx</a> :<br> &gt;<br> &gt; &quot;Note =A0The application should call this function in preference = to<br> &gt; GetUserDefaultLCID if designed to run only on Windows Vista and<br> &gt; later.&quot;<br> &gt;<br> &gt; It&#39;s not in kernel32.lib distributed with DMD. You would have to<b= r> &gt; create an OMF import lib by calling implib /system kernel32.dll (your<= br> &gt; own kernel32.dll) if you&#39;re actually using Vista or a newer OS and= <br> &gt; then linking with that. But you can say goodbye to supporting Windows<= br> &gt; older than Vista.<br> &gt;<br> &gt; OTOH GetUserDefaultLCID /is/ in the kernel32.lib distributed with DMD.= <br> &gt; So why not use that?<br> <br> </div></div>Lloyd, if the program you&#39;re writing is designed to be sold= or distributed<br> to the public then I&#39;d highly recommend against doing anything that req= uires<br> at least Vista. From what I&#39;ve heard, the adoption rates of Vista and W= in7<br> haven&#39;t been very good and about half of the Windows systems out there = are<br> still XP and pretty much holding there. A *lot* of Windows users are<br> deliberately sticking with XP, and you&#39;ll be loosing a lot of people.<b= r> <br> Of course, if your software is only designed to be used internally by some<= br> company, or just for you own use, etc., then obviously it doesn&#39;t matte= r...<br> <br> <br> </blockquote></div>Actually, Windows 7 is growing somewhat exponentially an= d XP is falling, though that fall isn&#39;t accelerating too rapidly. Howev= er, XP still sits at around 45%. --0016369fa152cd5f4a04a4b42e84--
Jun 01 2011
prev sibling parent reply Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
From what I can tell you're using the wide version, so try prototyping

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.
Jun 01 2011
next sibling parent "Lloyd Dupont" <ld-REMOVE galador.net> writes:
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

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.
Jun 01 2011
prev sibling parent "Lloyd Dupont" <ld-REMOVE galador.net> writes:
Thanks for the quick answers hey!

Another quick one (it's time to go to work for me!)
Does this lib contains the MSI function?

"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

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.
Jun 01 2011