Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 4th, 2004, 12:14 AM
ehboym ehboym is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 19 ehboym User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 58 m 48 sec
Reputation Power: 0
Question Reading unicode from INI

hi,

I need to read unicode strings from a unicode encoded INI in to a Visual Basic 6 Text Control (A forms 2 control).

Normally I would use the GetPrivateProfileString function to read from an INI but once the file is encoded in unicode the function return "?????" instead of the real string.

Opening the INI with notepad I can see the real string but the GetPrivateProfileStringW function wont read it.

Any suggestions on how to read it correctly ?

Thanks

EB

Reply With Quote
  #2  
Old January 4th, 2004, 03:28 AM
robbage robbage is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: Perth, Western Australia
Posts: 30 robbage User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via ICQ to robbage
Private Declare Function GetPrivateProfileString& Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal SectionName$, ByVal KeyName$, ByVal Default$, ByVal ReturnedString$, ByVal Size&, ByVal Filename$)

Reply With Quote
  #3  
Old January 4th, 2004, 03:33 AM
robbage robbage is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: Perth, Western Australia
Posts: 30 robbage User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via ICQ to robbage
Oops I meant to comment that post!

Try the Function ending with "A"

Reply With Quote
  #4  
Old January 4th, 2004, 10:00 AM
ehboym ehboym is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 19 ehboym User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 58 m 48 sec
Reputation Power: 0
Using the GetPrivateProfileStringA function creates a fatal error:
"The instruction at "0x77e931b6" referenced memory as "0x000000ff". The memory could not be "read".

It happens on tree different machine so I don't think it's a problem with the DLL.

The code I run is:
Private Sub Form_Load()
Dim ReturnValueSize As Long
Dim ReturnValue As String
Dim IniFileName As String

IniFileName = ("C:\Documents and Settings\dp18382\Desktop\Tirgolimos\Language Tester.ini")
ReturnValue = Space$(255)
ReturnValueSize = GetPrivateProfileStringA("Languages", "L1", " ", ReturnValue, Len(ReturnValue), IniFileName)
ReturnValue = Left(ReturnValue, ReturnValueSize)
End Sub


Any suggestions ?

EB

Reply With Quote
  #5  
Old January 4th, 2004, 10:14 AM
ehboym ehboym is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 19 ehboym User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 58 m 48 sec
Reputation Power: 0
Uops ... My mistake .. the function call is OK


BUT

it still wont return Spanish special letters.

The INI file is encoded using Unicode (In notepad, save as, encoding = Unicode). I can see the characters in notepad but reading it using GetPrivateProfileStringA ends up as a string where the special characters are ??.

GetPrivateProfileStringW return with an empty string.

Any ideas ?

EB

Reply With Quote
  #6  
Old January 4th, 2004, 11:23 AM
Doug G Doug G is offline
Grumpier Old Moderator
Dev Shed God 12th Plane (10500 - 10999 posts)
 
Join Date: Jun 2003
Posts: 10,852 Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 47 m 6 sec
Reputation Power: 766
I don't know if this will help or not.

http://msdn.microsoft.com/library/e...l/anch_mslu.asp

Reply With Quote
  #7  
Old January 5th, 2004, 12:54 AM
ehboym ehboym is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 19 ehboym User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 58 m 48 sec
Reputation Power: 0
Am I using it wrong ?

ReturnValue = Space$(255)
MBReturnValue = Space$(255)
ReturnValueSize = GetPrivateProfileStringA("Languages", "L1", " ", ReturnValue, Len(ReturnValue), IniFileName)
ReturnValue = Left(ReturnValue, ReturnValueSize)
ReturnValueSize = WideCharToMultiByte(0, 0, ReturnValue, ReturnValueSize, MBReturnValue, Len(MBReturnValue), "-", Flag)
MBReturnValue = Left(MBReturnValue, ReturnValueSize)
Label1.Caption = StrConv(MBReturnValue, vbUnicode, 2058)


When the file is encoded as UTF-8 or Unicode the end value it Label1.Caption is "-" instead of "Espaņol".

EB

Reply With Quote
  #8  
Old January 5th, 2004, 04:43 PM
robbage robbage is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: Perth, Western Australia
Posts: 30 robbage User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via ICQ to robbage
What did you get before? Something like "Espa?nol" ? Do you need to also use the correct font? <guessing here>

Reply With Quote
  #9  
Old January 6th, 2004, 12:03 AM
ehboym ehboym is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 19 ehboym User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 58 m 48 sec
Reputation Power: 0
Yep using the original lines I had received "Espa?nol".
As long as the letter is in the standard Western range of the Unicode it looks OK any letter out of that range is "?".

Changing fonts did not have any impact. In any case I'm using Arial MS Unicode which should have both English, Spanish...

Reply With Quote
  #10  
Old January 6th, 2004, 03:16 AM
robbage robbage is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: Perth, Western Australia
Posts: 30 robbage User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via ICQ to robbage
I'm not sure what is causing this but a solution that comes to mind is to use GetPrivateProfileStringA and convert the result with StrConv(result,vbFromUnicode).

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Reading unicode from INI


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway