-
Mar 3rd, 2021, 03:29 PM
#1
Thread Starter
Addicted Member
[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?
-
Mar 3rd, 2021, 04:05 PM
#2
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
-
Mar 3rd, 2021, 04:10 PM
#3
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.
-
Mar 3rd, 2021, 04:16 PM
#4
Re: Registry functions & Unicode values
Originally Posted by wqweto
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?
-
Mar 3rd, 2021, 04:16 PM
#5
Thread Starter
Addicted Member
Re: Registry functions & Unicode values
Originally Posted by wqweto
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.
-
Mar 3rd, 2021, 04:21 PM
#6
Thread Starter
Addicted Member
Re: Registry functions & Unicode values
Originally Posted by Arnoutdv
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.
-
Mar 3rd, 2021, 04:28 PM
#7
Thread Starter
Addicted Member
Re: Registry functions & Unicode values
Originally Posted by dilettante
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.
-
Mar 3rd, 2021, 04:42 PM
#8
Re: Registry functions & Unicode values
Originally Posted by Erwin69
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
-
Mar 3rd, 2021, 04:46 PM
#9
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?
-
Mar 3rd, 2021, 05:21 PM
#10
Thread Starter
Addicted Member
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!
-
Mar 3rd, 2021, 05:33 PM
#11
Re: Registry functions & Unicode values
Originally Posted by Erwin69
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|