Opened 3 years ago

Closed 3 years ago

#3821 closed Bug (Fixed)

_WinAPI_OemToChar should be forced to ASCII

Reported by: Nine Owned by: Jpm
Milestone: Component: AutoIt
Version: Severity: None
Keywords: Cc:


As per this thread :

Under certain conditions, the API switches to Unicode causing the script to crash. By forcing the function to use ASCII characters, the issue was solved. The revised function should look like this :

Func _WinAPI_OemToChar($sStr)
  Local $aRet = DllCall('user32.dll', 'bool', 'OemToCharA', 'str', $sStr, 'str', '')
  If @error Or Not $aRet[0] Then Return SetError(@error + 10, @extended, '')
  Return $aRet[2]
EndFunc   ;==>_WinAPI_OemToChar

Attachments (0)

Change History (3)

comment:2 Changed 3 years ago by Jpm

Not sure the title is the right way to describe that when using _WinAPI_OemToChar() with string greater than 65536 a crash occurs
The pb is the same for _WinAPI_CharToOem()
the right solution is

Func _WinAPI_OemToChar($sStr)
	Local $aCall, $sRetStr = "", $nLen = StringLen($sStr) + 1, $iStart = 1

	While $iStart < $nLen
		$aCall = DllCall('user32.dll', 'bool', 'OemToCharA', 'str', StringMid($sStr, $iStart, 65536), 'str', '')
		If @error Or Not $aCall[0] Then Return SetError(@error + 10, @extended, '')
		$sRetStr &= $aCall[2]
		$iStart += 65536

	Return $sRetStr
EndFunc   ;==>_WinAPI_OemToChar

comment:3 Changed 3 years ago by Jpm

  • Milestone set to
  • Owner set to Jpm
  • Resolution set to Fixed
  • Status changed from new to closed

Fixed by revision [12536] in version:

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

as closed The owner will remain Jpm.

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.