Page 1 of 1

Get Localized Strings From Windows System DLLs

Posted: Wed Nov 16, 2011 11:33 am
by gnozal
May be useful to build simple custom requesters (like MessageRequester).

Code: Select all

;
; Get Localized Strings From Windows System DLLs
;
;{ some valid uIDs ...
; USER32
#LocalString_Error = 2
#LocalString_OK = 800
#LocalString_Cancel = 801
#LocalString_Abort = 802
#LocalString_Retry = 803
#LocalString_Ignore = 804
#LocalString_Yes = 805
#LocalString_No = 806
#LocalString_Close = 807
#LocalString_Help = 808
#LocalString_TryAgain = 809
#LocalString_Continue = 810
#LocalString_Minimize = 900
#LocalString_Maximize = 901
#LocalString_RestoreUp = 902
#LocalString_RestoreDown = 903
; COMDLG32
#LocalString_Save = 369
#LocalString_Open = 370
#LocalString_Print = 371
#LocalString_SaveAs = 385
; SHELL32
#LocalString_File = 4130
#LocalString_Folder = 4131
#LocalString_Move = 4144
#LocalString_Copy = 4145
#LocalString_Delete = 4146
#LocalString_Rename = 4147
;}
Procedure.s GetLocaleString(uID) ; Get Localized Strings ['' if invalid uID]
  ;
  Protected LocaleString.s, hInstance, *Buffer, WinLibrary.s
  ;
  If uID >= #LocalString_File
    WinLibrary = "shell32"
  ElseIf uID >= #LocalString_Save And uID <= #LocalString_SaveAs
    WinLibrary = "comdlg32"
  Else
    WinLibrary = "user32"
  EndIf
  ;
  hInstance = LoadLibraryEx_(WinLibrary, 0, #LOAD_LIBRARY_AS_DATAFILE)
  If hInstance
    ;
    *Buffer = AllocateMemory(256)
    If *Buffer
      ;
      If LoadString_(hInstance, uID, *Buffer, 255)
        LocaleString = PeekS(*Buffer)
        LocaleString = RemoveString(LocaleString, "&")
      EndIf
      FreeMemory(*Buffer)
      ;
    EndIf
    ;
    FreeLibrary_(hInstance)
    ;
  EndIf
  ;
  ProcedureReturn LocaleString
  ;
EndProcedure

Debug GetLocaleString(#LocalString_Yes) ; -> Yes / Oui / Ja / ...
Debug GetLocaleString(#LocalString_Print) ; -> Print / Imprimer ...
Could you test if it works on Vista / Se7en ?

Re: Get Localized Strings From Windows System DLLs

Posted: Wed Nov 16, 2011 12:07 pm
by srod
Works fine on Vista x86 Gnozal.

Could indeed be useful - thanks.

You're not still using that NT rubbish are you? :wink:

Re: Get Localized Strings From Windows System DLLs

Posted: Wed Nov 16, 2011 12:09 pm
by gnozal
srod wrote:You're not still using that NT rubbish are you? :wink:
Nope ...

XP :lol:

Re: Get Localized Strings From Windows System DLLs

Posted: Wed Nov 16, 2011 12:24 pm
by srod
gnozal wrote:
srod wrote:You're not still using that NT rubbish are you? :wink:
Nope ...

XP :lol:
Ah, progress! :)

Re: Get Localized Strings From Windows System DLLs

Posted: Thu Nov 17, 2011 7:48 am
by Little John
Thank you, gnozal!

Regards, Little John

Re: Get Localized Strings From Windows System DLLs

Posted: Thu Nov 17, 2011 12:27 pm
by einander
Thanks gnozal.
Works fine on seven x86 and x64.

Re: Get Localized Strings From Windows System DLLs

Posted: Tue Apr 03, 2012 6:26 pm
by Little John
Hi gnozal,

do you think it's possible also to get the localized names of weekdays and months in a similar way? That would be useful as well.
On my system (German Windows XP Pro SP3 32bit), complete and abbreviated localized names of weekdays and months are contained in the file "C:\Windows\System32\ole2nls.dll".

Regards, Little John

Re: Get Localized Strings From Windows System DLLs

Posted: Wed Apr 04, 2012 9:48 am
by Kwai chang caine
Thanks for sharing, GNOZAL works good 8)

Re: Get Localized Strings From Windows System DLLs

Posted: Fri Apr 06, 2012 11:09 am
by gnozal
Little John wrote:do you think it's possible also to get the localized names of weekdays and months in a similar way? That would be useful as well.
On my system (German Windows XP Pro SP3 32bit), complete and abbreviated localized names of weekdays and months are contained in the file "C:\Windows\System32\ole2nls.dll".
LoadLibraryEx_() fails probably because "ole2nls.dll" is a NE executable (16 bits).

But you could use GetLocaleInfo_() :

Code: Select all

;
; Get Localized Day Or Month Name
;
Procedure.s LocalizedDayName(DayOfWeek)
  Protected DayName.s
  DayName = Space(80)
  GetLocaleInfo_(#LOCALE_USER_DEFAULT, #LOCALE_SDAYNAME1 + DayOfWeek - 1, @DayName, 80) ; LOCALE_SABBREVDAYNAME1 -> short name
  ProcedureReturn DayName
EndProcedure
Procedure.s LocalizedMonthName(MonthOfYear)
  Protected MonthName.s
  MonthName = Space(80)
  GetLocaleInfo_(#LOCALE_USER_DEFAULT, #LOCALE_SMONTHNAME1 + MonthOfYear - 1, @MonthName, 80) ; LOCALE_SABBREVMONTHNAME1 -> short name
  ProcedureReturn MonthName
EndProcedure

For i = 1 To 7
  Debug LocalizedDayName(i)
Next
Debug "--------"
For i = 1 To 12
  Debug LocalizedMonthName(i)
Next

Re: Get Localized Strings From Windows System DLLs

Posted: Sun Apr 08, 2012 9:04 am
by Little John
GREAT!!!
Thank you very much, Gnozal!