Sign in to follow this  
Followers 0
Polyphem

OEM2ANSI Problem... [Solved?]

4 posts in this topic

#1 ·  Posted (edited)

Hi Folks,

I got a problem with the oem2ansi function provided below...

MsgBox(0,"",_OEM2ANSI(_ANSI2OEM("é")))
MsgBox(0,"",_OEM2ANSI(_ANSI2OEM("è")))
MsgBox(0,"",_OEM2ANSI(_ANSI2OEM("ç")))
MsgBox(0,"",_OEM2ANSI(_ANSI2OEM("ã")))

MsgBox(0,"",_OEM2ANSI(_ANSI2OEM("")))

Func _OEM2ANSI($what)
    $ret = DllCall('user32.dll', 'Int', 'OemToChar', 'str', $what, 'str', '')
    Return $ret[2]
EndFunc   ;==>_OEM2ANSI

Func _ANSI2OEM($what)
    $ret = DllCall('user32.dll', 'Int', 'CharToOem', 'str', $what, 'str', '')
    Return $ret[2]
EndFunc   ;==>_OEM2ANSI

The first 4 characters are interpreted correct, but the 5th isn't.... instead of the expected

the result is

'

.... anyone got a hint for me?

Thanks and Cheers

Poly

Edited by Polyphem

This post will be edited again by Polyphem: Tomorrow, 11:55 AM

Share this post


Link to post
Share on other sites



Hmmmm, the real problem is even a little bit more complicated...

What I tried was to capture a @comspec dir command... but the reply is already false... windows explorer shows a ,cmd.exe dir shows a ,

(manual input only, an

$scan_Pid = Run("c:\windows\system32\cmd.exe" & ' /k ' & 'dir "' & $sPath & '\' & "*.*" & '" /-c /A:-D /S', '', @SW_HIDE, 6)

also replies a ' instead of an ,

a @comspec dir replies a ', so that I even cant capture the character for a workaround in the oem2ansi function (e.g. with stringinstr).... it's also related to this discussion....

#520173

In the SmOke_N version the problem with DOS 'foreign' chars is simply due to DOS using OEM codepage.

So the solution is simple. Translate filenames from Oem To Ansi.

Maybe there is a way to switch the codepage used before execution?

This post will be edited again by Polyphem: Tomorrow, 11:55 AM

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Took quiet some time to find a working piece of code for this one :D , no worries, didnt search fulltime ;) ...

#include "Constants.au3"

; create a file "äßöüßü^.txt" in the script root... notice the difference in the msgbox regarding the output of 
; in the OEM2ANSI version the output for  is '
; in the CHCP1252 version the output for  is 
;
; of course the codepage can be set to anything you need : ).... reference for windows codepages can be found here http://www.microsoft.com/globaldev/reference/cphome.mspx

;---------------------------------------- @ComSpec with _OEM2ANSI ---------------------------------
$line = ""
$foo = Run(@ComSpec & " /c dir", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
While 1
    $line &= StdoutRead($foo)
    If @error Then ExitLoop
Wend

$output_comspec_oem2ansi = _OEM2ANSI($line)

;---------------------------------------- @ComSpec with chcp 1252 ---------------------------------
$line = ""
$foo = Run(@ComSpec, "", @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD)
StdinWrite($foo, "chcp 1252" & @CRLF) ; change codepage for cmd.exe instance to 1252 (West European Latin)
StdinWrite($foo, "dir" & @CRLF)
StdinWrite($foo, "exit" & @CRLF) ; send exit command to trigger stdout
While 1
    $line &= StdoutRead($foo)
    If @error Then ExitLoop
Wend
$keyword_dir = stringinstr($line,">dir")+6 ; to purge the output of the "chcp 1252" command
$keyword_colon = stringinstr($line,":",0,-1)-5 ; to purge the output of the "exit" command
$line = StringMid($line,$keyword_dir,stringlen($line)-(stringlen($line)-$keyword_colon)-$keyword_dir)

$output_comspec_chcp1252 = $line

;---------------------------------------- Output ---------------------------------

MsgBox(0, "Stdout OEM2ANSI", $output_comspec_oem2ansi)
MsgBox(0, "Stdout chcp 1252", $output_comspec_chcp1252)

Exit

;---------------------------------------- Func ---------------------------------

Func _OEM2ANSI($what)
    $ret = DllCall('user32.dll', 'Int', 'OemToChar', 'str', $what, 'str', '')
    Return $ret[2]
EndFunc   ;==>_OEM2ANSI

For me it works fine this way. Anyone got reasons why not to use Codepage 1252? Though I fear it would only work for Western Code. Any comments are welcome...

Cheers

Edited by Polyphem

This post will be edited again by Polyphem: Tomorrow, 11:55 AM

Share this post


Link to post
Share on other sites

Took quiet some time to find a working piece of code for this one :( , no worries, didnt search fulltime :graduated: ...

#include "Constants.au3"

; create a file "äßöüßü^.txt" in the script root... notice the difference in the msgbox regarding the output of 
; in the OEM2ANSI version the output for  is '
; in the CHCP1252 version the output for  is 
;
; of course the codepage can be set to anything you need : ).... reference for windows codepages can be found here http://www.microsoft.com/globaldev/reference/cphome.mspx

;---------------------------------------- @ComSpec with _OEM2ANSI ---------------------------------
$line = ""
$foo = Run(@ComSpec & " /c dir", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
While 1
    $line &= StdoutRead($foo)
    If @error Then ExitLoop
Wend

$output_comspec_oem2ansi = _OEM2ANSI($line)

;---------------------------------------- @ComSpec with chcp 1252 ---------------------------------
$line = ""
$foo = Run(@ComSpec, "", @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD)
StdinWrite($foo, "chcp 1252" & @CRLF) ; change codepage for cmd.exe instance to 1252 (West European Latin)
StdinWrite($foo, "dir" & @CRLF)
StdinWrite($foo, "exit" & @CRLF) ; send exit command to trigger stdout
While 1
    $line &= StdoutRead($foo)
    If @error Then ExitLoop
Wend
$keyword_dir = stringinstr($line,">dir")+6 ; to purge the output of the "chcp 1252" command
$keyword_colon = stringinstr($line,":",0,-1)-5 ; to purge the output of the "exit" command
$line = StringMid($line,$keyword_dir,stringlen($line)-(stringlen($line)-$keyword_colon)-$keyword_dir)

$output_comspec_chcp1252 = $line

;---------------------------------------- Output ---------------------------------

MsgBox(0, "Stdout OEM2ANSI", $output_comspec_oem2ansi)
MsgBox(0, "Stdout chcp 1252", $output_comspec_chcp1252)

Exit

;---------------------------------------- Func ---------------------------------

Func _OEM2ANSI($what)
    $ret = DllCall('user32.dll', 'Int', 'OemToChar', 'str', $what, 'str', '')
    Return $ret[2]
EndFunc   ;==>_OEM2ANSI

For me it works fine this way. Anyone got reasons why not to use Codepage 1252? Though I fear it would only work for Western Code. Any comments are welcome...

Cheers

Great work it helped a lot

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0