Jump to content



Photo

OEM2ANSI Problem... [Solved?]


  • Please log in to reply
3 replies to this topic

#1 Polyphem

Polyphem

    Adventurer

  • Active Members
  • PipPip
  • 125 posts

Posted 04 August 2008 - 03:53 PM

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, 05 September 2008 - 05:51 PM.

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





#2 Polyphem

Polyphem

    Adventurer

  • Active Members
  • PipPip
  • 125 posts

Posted 04 August 2008 - 05:10 PM

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....

http://www.autoitscript.com/forum/index.ph...st&p=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

#3 Polyphem

Polyphem

    Adventurer

  • Active Members
  • PipPip
  • 125 posts

Posted 05 September 2008 - 05:42 PM

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

AutoIt         
#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 <a href='http://www.microsoft.com/globaldev/reference/cphome.mspx' class='bbc_url' title='External link' rel='nofollow external'>http://www.microsoft.com/globaldev/reference/cphome.mspx</a> ;---------------------------------------- @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, 05 September 2008 - 05:56 PM.

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

#4 CNCMONKEY

CNCMONKEY

    Seeker

  • Active Members
  • 8 posts

Posted 06 November 2010 - 11:30 AM

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

AutoIt         
#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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users