Results 1 to 11 of 11

Thread: [RESOLVED] Registry functions & Unicode values

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2012
    Posts
    245

    Resolved [RESOLVED] Registry functions & Unicode values

    In my quest to implement full Unicode support in my apps, I ran into something strange.

    When I use the SaveSetting to store a value in the registry, a Unicode value like “Русский” is stored without problems. However, when I use the GetSetting function to retrieve the value of that same key, I just get a bunch of ?????

    I would expect both of them to handle Unicode values, or both not. However, saving ok, but not loading back, doesn’t make sense if you ask me.

    Anyone had this same experience? If so, how did you solve it? By using API calls?

  2. #2
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    Re: Registry functions & Unicode values

    95% sure this is programming error in *your* code, probably wrong API declare or param but the Q without code is non-actionable per se

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Registry functions & Unicode values

    Better to avoid problems like registry fragmentation and virtualization. SaveSetting/GetSetting are obsolete old ANSI operations carried over from 16-bit VB.

    If you insist on this instead of using settings files (INI, XML, JSON, ad hoc, etc.) then you would have to use the registry API calls or some registry library with a class for registry operations like WScript.Shell for example. That also gets you past potential disasters from relying coercion to and from String typed data as well as ANSI conversions.

  4. #4
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,871

    Re: Registry functions & Unicode values

    Quote Originally Posted by wqweto View Post
    95% sure this is programming error in *your* code, probably wrong API declare or param but the Q without code is non-actionable per se
    SaveSetting and GetSetting are intrinsic VB6 methodes.
    Can you retrieve the value incorrectly using GetSetting?

    When I use the SaveSetting to store a value in the registry, a Unicode value like “Русский” is stored without problems. However, when I use the GetSetting function to retrieve the value of that same key, I just get a bunch of ?????
    Just to be sure, did you check whether the value is correctly stored in the registry using RegEdit?

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jan 2012
    Posts
    245

    Re: Registry functions & Unicode values

    Quote Originally Posted by wqweto View Post
    95% sure this is programming error in *your* code, probably wrong API declare or param but the Q without code is non-actionable per se
    Bit of a strange reply, as I'm referring to the standard GetSetting/SaveSetting functions, nothing to do with API declares or parameters...

    But here is some code to look at:

    Code:
    Dim sLanguage As String
    
    SaveSetting Appname:="ABC", Section:="Options", Key:="Language", Setting:=cmbUILanguage.Text
    
    sLanguage = GetSetting(Appname:="ABC", Section:="Options", Key:="Language", Default:="English")
    Where cmbUILanguage is a ComboBoxW control from Krool's Common Controls Replacements that offer full unicode support.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jan 2012
    Posts
    245

    Re: Registry functions & Unicode values

    Quote Originally Posted by Arnoutdv View Post
    SaveSetting and GetSetting are intrinsic VB6 methodes.
    Can you retrieve the value incorrectly using GetSetting?


    Just to be sure, did you check whether the value is correctly stored in the registry using RegEdit?
    Thanks Arnout. I did indeed check the value via RegEdit, and yep, it's correctly saved there. That's what I found surprising; saving worked fine, but retrieving not.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jan 2012
    Posts
    245

    Re: Registry functions & Unicode values

    Quote Originally Posted by dilettante View Post
    Better to avoid problems like registry fragmentation and virtualization. SaveSetting/GetSetting are obsolete old ANSI operations carried over from 16-bit VB.

    If you insist on this instead of using settings files (INI, XML, JSON, ad hoc, etc.) then you would have to use the registry API calls or some registry library with a class for registry operations like WScript.Shell for example. That also gets you past potential disasters from relying coercion to and from String typed data as well as ANSI conversions.
    Thanks Dilettante. Interesting that we're first "pushed" to move away from ini-files towards the registry, and now basically back to settings-files again...

    I will take that into consideration for future work, but for now it would be an awful amount of work, as settings stored in the registry are used across the whole application. I guess the best option at this point it to wrap something around the API's. I already noticed some posts about those / a registry class.

  8. #8
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,995

    Re: Registry functions & Unicode values

    Quote Originally Posted by Erwin69 View Post
    for now it would be an awful amount of work, as settings stored in the registry are used across the whole application. I guess the best option at this point it to wrap something around the API's. I already noticed some posts about those / a registry class.
    You could override (in a bas module) GetSetting, SaveSetting, DeleteSetting and GetAllSetttings with your own functions.

    Then you can "easily" opt for using INI files or registry API calls, or encode the strings with Base64 and use the normal VB6 functions.

    To call the VB functions, precede them with VBA:

    Code:
    Public Function GetSetting(AppName As String, Section As String, Key As String, Optional Default) As String
        GetSetting = Base64Decode(VBA.GetSetting(AppName, Section, Key, Default))
    End Function
    
    Public Sub SaveSetting(AppName As String, Section As String, Key As String, Setting As String)
        VBA.SaveSetting AppName, Section, Key, Base64Encode(Setting)
    End Sub

  9. #9
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Registry functions & Unicode values

    I just tested this and Unicode text was both written and read, so my impression that they do conversions to/from ANSI is clearly incorrect.

    So that only leaves some other program bug as the cause, because I can fetch Unicode text just fine.

    If you were using Debug.Print or MsgBox(), those both do conversion to ANSI so maybe that was your mistake?

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Jan 2012
    Posts
    245

    Re: Registry functions & Unicode values

    You are correct Dilettante, my conclusion that the GetSetting function didn't read the unicode value was wrong. I was passing on the value to a function that uses the OpenFile API, which doesn't support unicode, and thus was causing the error. I have my work set out for me...

    @Eduardo, thanks for the tips!

  11. #11
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    Re: Registry functions & Unicode values

    Quote Originally Posted by Erwin69 View Post
    Bit of a strange reply, as I'm referring to the standard GetSetting/SaveSetting functions, nothing to do with API declares or parameters...

    But here is some code to look at:

    Code:
    Dim sLanguage As String
    
    SaveSetting Appname:="ABC", Section:="Options", Key:="Language", Setting:=cmbUILanguage.Text
    
    sLanguage = GetSetting(Appname:="ABC", Section:="Options", Key:="Language", Default:="English")
    Where cmbUILanguage is a ComboBoxW control from Krool's Common Controls Replacements that offer full unicode support.
    Oops! I thought you were migrating *away* from ANSI based Get/SaveSettings to an all API alt Unicode implementation.

    Glad you figured it out.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width