Re: how to get the local?

2011-06-01 Thread Andrew Wiley
On Thu, Jun 2, 2011 at 12:23 AM, Nick Sabalausky  wrote:

> "Andrej Mitrovic"  wrote in message
> news:mailman.521.1306960464.14074.digitalmars-d-le...@puremagic.com...
> > >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?
>
> 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,
though that fall isn't accelerating too rapidly. However, XP still sits at
around 45%.


Re: how to get the local?

2011-06-01 Thread Nick Sabalausky
"Andrej Mitrovic"  wrote in message 
news:mailman.521.1306960464.14074.digitalmars-d-le...@puremagic.com...
> >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?

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...




Stack traces when stack overflow

2011-06-01 Thread bearophile
This crashes at runtime because of a stack overflow, without stack frame or 
error message (DMD 2.053), no stack trace, or line number are shown:


int foo(int n) {
return n ? foo(n - 1) : 1;
}
void main() {
foo(100_000);
}


If you aren't running a debugger then receiving a nude crash is not so nice, 
because in a larger program there are many functions that may be the cause of 
such stack overflow. So is it possible to add some stack protection code (in 
non-release mode only, if necessary) to receive a stack trace in this case?

Bye,
bearophile


Re: 2 question: internationalization and serialization

2011-06-01 Thread Jérôme M. Berger
Andrej Mitrovic wrote:
> You need mercurial and do 'hg clone
> http://hg.dsource.org/projects/orange' from the command line.

Or you can just click on the "zip", "gz" or "bz2" button at the top
of http://hg.dsource.org/projects/orange if you do not care about
the history.

Jerome
-- 
mailto:jeber...@free.fr
http://jeberger.free.fr
Jabber: jeber...@jabber.fr



signature.asc
Description: OpenPGP digital signature


Re: how to get the local?

2011-06-01 Thread Andrej Mitrovic
On 6/1/11, Steven Schveighoffer  wrote:
> On Wed, 01 Jun 2011 16:38:05 -0400, Andrej Mitrovic
>  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 
> 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 
> 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.


Re: how to get the local?

2011-06-01 Thread Lloyd Dupont

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 
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).



Re: how to get the local?

2011-06-01 Thread Lloyd Dupont

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-le...@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. 



Re: how to get the local?

2011-06-01 Thread Steven Schveighoffer
On Wed, 01 Jun 2011 16:38:05 -0400, Andrej Mitrovic  
 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

FromAndrej Mitrovic 
DateWed, 1 Jun 2011 22:34:15 +0200

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


FromSteven Schveighoffer 
DateWed, 01 Jun 2011 16:34:13 -0400

Note also the ordering of the article ids ;)

so THERE!

-Steve


Re: how to get the local?

2011-06-01 Thread Andrej Mitrovic
I beat you Steven!!

:P


Re: 2 question: internationalization and serialization

2011-06-01 Thread Andrej Mitrovic
You need mercurial and do 'hg clone
http://hg.dsource.org/projects/orange' from the command line.


Re: how to get the local?

2011-06-01 Thread Steven Schveighoffer
On Wed, 01 Jun 2011 16:13:44 -0400, Lloyd Dupont   
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-le...@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.


Re: how to get the local?

2011-06-01 Thread Andrej Mitrovic
>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?


Re: 2 question: internationalization and serialization

2011-06-01 Thread Lloyd Dupont

I'm looking!
mm... how do I download the repository!?! :~


"Jacob Carlborg"  wrote in message news:is5msf$1lt0$1...@digitalmars.com... 

For the serialization you could have a look at Orange: 
http://www.dsource.org/projects/orange
Don't know if it works with the latest compilers, it's been a while 
since I updated the code. I'm also in the middle of complete rewrite of 
the library. At lease you can perhaps find some ideas.


--
/Jacob Carlborg


Re: 2 question: internationalization and serialization

2011-06-01 Thread Lloyd Dupont

Awesome! WIll take a look at it tonight!
Thanks for the link! :)

"Jacob Carlborg"  wrote in message news:is5msf$1lt0$1...@digitalmars.com... 


On 2011-06-01 14:51, Lloyd Dupont wrote:

Hi I'm a newbie with big ambitions! (Sorry, got spoiled by C#)

Anyhow I'm toying with a D learning project and there are 2 .NET feature
that will be welcome in this D project:

1. internationalization.
the app will contains a bunch of simple UIs and I was wondering how I
would go on internationalizing the application. I.e. embed multiple
"resource" for different languages in the EXE and show the appropriate
ones for the target / running computer


2. I'd like a part of my library (in progress) to read / write some
arbitrary settings. I was thing to use something akin to the
DataContractSerialization we have in .NET
where I could define a few classes with attribute

[DataContract]
class Root
{
[DataMember]
public int Prop1 { get; set; }
[DataMember]
public B PropB { get; set; }
}

[DataContract]
class B
{
[DataMember]
public string Name { get; set; }
}

a reader / writer class can turn this class (using the atributes) into
text (XML, JSON, I don't care) and back from text into object instance
How would I implement something similar in D? Is there already a library
doing it?


For the serialization you could have a look at Orange: 
http://www.dsource.org/projects/orange
Don't know if it works with the latest compilers, it's been a while 
since I updated the code. I'm also in the middle of complete rewrite of 
the library. At lease you can perhaps find some ideas.


--
/Jacob Carlborg


Re: how to get the local?

2011-06-01 Thread Lloyd Dupont

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-le...@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. 



Re: Clear big AAs

2011-06-01 Thread bearophile
useo:

> Is there anything I forgot to consider?

If the key and values are primitive values or structs of primitive values then 
you may try another AA implementation that doesn't use the GC.

Bye,
bearophile


Re: Clear big AAs

2011-06-01 Thread useo
== Auszug aus David Nadlinger (s...@klickverbot.at)'s Artikel
> I realize that this might sound strange, but try setting myAA to
null
> after clear(), this should fix the crash.
> David
> On 5/31/11 4:00 PM, useo wrote:
> > Hi,
> >
> > I'm trying to clear big associative arrays, but I always get an
> > object error - what I currently doing is:
> >
> > private string[uint] myAA;
> >
> > void main() {
> >
> > fill(myAA);
> > myAA.clear();
> > fill(myAA); // object.Error: Access Violation
> > }
> >
> > void fill(string[uint] aa) {
> > for (uint i = 0; i<  10_000_000_000; i++) {
> >myAA[i] = std.conv.to!(string)(i);
> > }
> > }
> >
> > I already saw the bug report at http://www.digitalmars.com/d/
archives/
> > digitalmars/D/bugs/
> >
Issue_5683_New_Calling_.clear_on_a_fresh_associative_array_causes_subsequent_segfault_28632.html
> > and I'm also using 2.052 - as I saw at the change-log of 2.053
it's
> > also unfixed. So... is there any solution to clear associative
arrays
> > without memory leaking?

Thanks a lot,

I solved it by using

pGraphics.clear();
pGraphics = null;
// pGraphics.rehash();

I thought this'll solve my problem, but it doesn't... I've to fill my
AA every 500 ms with around 250 values (in principle much less than
10_000_000_000). When I start my application (in this context, my
game), it works as needed (around 2000 fps/s) but after some seconds,
the fps-rate drops down to 1/s and back to normal (and again, and
again...). When I remove the command to clear the array, it works
without dropping down to 1 fps. I this case I can't update my screen
as needed. I also tried to delete the class instance which contains
the array and create an new but it's the same as before (it drops
down to 1 fps). Is there anything I forgot to consider?


Re: 2 question: internationalization and serialization

2011-06-01 Thread Jacob Carlborg

On 2011-06-01 14:51, Lloyd Dupont wrote:

Hi I'm a newbie with big ambitions! (Sorry, got spoiled by C#)

Anyhow I'm toying with a D learning project and there are 2 .NET feature
that will be welcome in this D project:

1. internationalization.
the app will contains a bunch of simple UIs and I was wondering how I
would go on internationalizing the application. I.e. embed multiple
"resource" for different languages in the EXE and show the appropriate
ones for the target / running computer


2. I'd like a part of my library (in progress) to read / write some
arbitrary settings. I was thing to use something akin to the
DataContractSerialization we have in .NET
where I could define a few classes with attribute

[DataContract]
class Root
{
[DataMember]
public int Prop1 { get; set; }
[DataMember]
public B PropB { get; set; }
}

[DataContract]
class B
{
[DataMember]
public string Name { get; set; }
}

a reader / writer class can turn this class (using the atributes) into
text (XML, JSON, I don't care) and back from text into object instance
How would I implement something similar in D? Is there already a library
doing it?


For the serialization you could have a look at Orange: 
http://www.dsource.org/projects/orange
Don't know if it works with the latest compilers, it's been a while 
since I updated the code. I'm also in the middle of complete rewrite of 
the library. At lease you can perhaps find some ideas.


--
/Jacob Carlborg


Re: nested class inheritance

2011-06-01 Thread Simen Kjaeraas
On Wed, 01 Jun 2011 01:57:52 +0200, Michael Shulman  
 wrote:



I've also realized that my proposed workaround actually doesn't work,
because 'alias this' doesn't actually behave like subclassing with
respect to references.  That is, if Inner2 is 'alias this'ed to
Inner1, and I try to pass an Inner2 object to a function that's
expecting an Inner1, it actually just passes the _self Inner1 object
which knows nothing about Inner2 any more--right?


Correct.

--
  Simen


Re: how to get the local?

2011-06-01 Thread Don

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:
Error1Error 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?


Re: how to get the local?

2011-06-01 Thread Steven Schveighoffer
On Wed, 01 Jun 2011 10:31:45 -0400, 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);
}
===
and compile and link to kernel32.lib

But I got the following compile error:
Error1Error 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


Re: how to get the local?

2011-06-01 Thread Andrej Mitrovic
>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.


Re: how to get the local?

2011-06-01 Thread Lloyd Dupont

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:
Error1Error 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? 



how to get the local?

2011-06-01 Thread Lloyd Dupont

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?


Re: 2 question: internationalization and serialization

2011-06-01 Thread Lloyd Dupont

I found half the answer to question 1 (internationalization)
I still dunno how to get the local language (I guess I'll have to find the 
win32 method which return it)



but I found how to do the resources!! (using mixins)
what do you think?

=== D file ===
string[string][string] lang;
mixin(import("lang.txt"));
mixin(import("lang.fr.txt"));

=== lang.txt ==
lang["en"] = [
"start" : "start",
"quit"  : "quit",
];

=== lang.fr.txt
lang["fr"] = [
"start" : "demarrer",
"quit"  : "quitter",
];


"Lloyd Dupont"  wrote in message news:is5cs7$128p$1...@digitalmars.com...

Hi I'm a newbie with big ambitions! (Sorry, got spoiled by C#)

Anyhow I'm toying with a D learning project and there are 2 .NET feature
that will be welcome in this D project:

1. internationalization.
the app will contains a bunch of simple UIs and I was wondering how I would
go on internationalizing the application. I.e. embed multiple "resource" for
different languages in the EXE and show the appropriate ones for the target
/ running computer


2. I'd like a part of my library (in progress) to read / write some
arbitrary settings. I was thing to use something akin to the
DataContractSerialization we have in .NET
where I could define a few classes with attribute

[DataContract]
class Root
{
 [DataMember]
 public int Prop1 { get; set; }
 [DataMember]
 public B PropB { get; set; }
}

[DataContract]
class B
{
 [DataMember]
 public string Name { get; set; }
}

a reader / writer class can turn this class (using the atributes) into text
(XML, JSON, I don't care) and back from text into object instance
How would I implement something similar in D? Is there already a library
doing it? 



2 question: internationalization and serialization

2011-06-01 Thread Lloyd Dupont

Hi I'm a newbie with big ambitions! (Sorry, got spoiled by C#)

Anyhow I'm toying with a D learning project and there are 2 .NET feature 
that will be welcome in this D project:


1. internationalization.
the app will contains a bunch of simple UIs and I was wondering how I would 
go on internationalizing the application. I.e. embed multiple "resource" for 
different languages in the EXE and show the appropriate ones for the target 
/ running computer



2. I'd like a part of my library (in progress) to read / write some 
arbitrary settings. I was thing to use something akin to the 
DataContractSerialization we have in .NET

where I could define a few classes with attribute

[DataContract]
class Root
{
 [DataMember]
 public int Prop1 { get; set; }
 [DataMember]
 public B PropB { get; set; }
}

[DataContract]
class B
{
 [DataMember]
 public string Name { get; set; }
}

a reader / writer class can turn this class (using the atributes) into text 
(XML, JSON, I don't care) and back from text into object instance
How would I implement something similar in D? Is there already a library 
doing it?