It is currently Thu Nov 21, 2019 11:14 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: OemToChar Bug
PostPosted: Mon Oct 07, 2019 7:35 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2046
Location: Germany
Problem with convert OEM to String... (OemToCharW not work correctly)

API or PB Bug with 'TAB'
Code:

Import ""
  OemToCharA(*scr, *dst)
  OemToCharW(*scr, *dst)
EndImport

CompilerIf #PB_Compiler_Version < 550
  Procedure Ascii(Text.s)
    Protected *mem
    *mem = AllocateMemory(Len(text) + 1)
    PokeS(*mem, Text, -1, #PB_Ascii)
    ProcedureReturn *mem
  EndProcedure
CompilerEndIf


Procedure.s OemToString(in.s)
  Protected r1, out.s, *pScr, *pDst, i, cnt
 
  *pScr = Ascii(in)
  *pDst = AllocateMemory(Len(in) * 2 + 2)
  r1 = OemToCharW(*pScr, *pDst)
  out = PeekS(*pDst, -1, #PB_Unicode)
  FreeMemory(*pScr)
  FreeMemory(*pDst)

  ProcedureReturn out
 
EndProcedure

Procedure.s OemToAscII(in.s)
  Protected r1, out.s, *pScr, *pDst, i, cnt
 
  *pScr = Ascii(in)
  *pDst = AllocateMemory(Len(in) * 1 + 2)
  r1 = OemToCharA(*pScr, *pDst)
  out = PeekS(*pDst, -1, #PB_Ascii)
  FreeMemory(*pScr)
  FreeMemory(*pDst)

  ProcedureReturn out
 
EndProcedure

Procedure OemWriteStringN(File, Text.s)
  Protected r1, *pDst, len
 
  text + #CRLF$
  len = Len(text)
  *pDst = AllocateMemory(len + 2)
  CharToOem_(@Text, *pDst)
  r1 = WriteData(File, *pDst, len)
  FreeMemory(*pDst)
  ProcedureReturn r1
EndProcedure

; OEM String
a.s = "1808     18   P„ck   PŽCK"

;ShowMemoryViewer(@a, 64)
b.s = OemToString(a)
c.s = OemToAscII(a)
Debug "Bug: " + b
Debug "Ok: " + c

ShowMemoryViewer(@b, 64)

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: OemToChar Bug
PostPosted: Fri Oct 11, 2019 5:19 am 
Offline
User
User
User avatar

Joined: Wed Jun 27, 2018 5:12 am
Posts: 10
Hey,
No bug. As we know, the OEM is used by Win32 console applications, it came with DOS CP437.
The misnomer ANSI is used for non-unicode GUI applications.
A Chr(9) TAB character appearance is a "white circle".
With OemToChar(), the TAB character is Chr(9) for both OEM and "Ansi", this is why you got good result.
With OemToCharW(), the TAB character is Chr(9) for OEM and Chr(0x25CB) for unicode "white circle".
Function see TAB as a printable character and not as a control character.

You may use CharToOem() and then convert to unicode with MultiByteToWideChar(%CP_ACP,...)
or use CharToOemW() and then replace unicode Chr(0x25CB) with Chr(0x0900).
Note that CR and LF will need the same kind of attention.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye