Sign in to follow this  
Followers 0
jezzzzy

_Utf82Unicode & _Unicode2Asc Question

7 posts in this topic

Using these 2 functions like this:

$wTrayTitle = _Unicode2Asc(_Utf82Unicode(StringStripWS($wTitle[0],7)))

However the function for _Utf82Unicode has a line in it that uses StringLeft. This is stripping needed characters from my string.

Func _Utf82Unicode($Utf8String)
    Local $BufferSize = StringLen($Utf8String) * 2
    Local $Buffer = DllStructCreate("byte[" & $BufferSize & "]")
    Local $Return = DllCall("Kernel32.dll", "int", "MultiByteToWideChar", _
        "int", 65001, _
        "int", 0, _
        "str", $Utf8String, _
        "int", StringLen($Utf8String), _
        "ptr", DllStructGetPtr($Buffer), _
        "int", $BufferSize)
   ;Local $UnicodeString = StringLeft(DllStructGetData($Buffer, 1), $Return[0] * 2)
    Local $UnicodeString = DllStructGetData($Buffer, 1)
    $Buffer = 0
    Return $UnicodeString 
EndFunc

Is there any problem with removing the StringLeft function like this:?

Local $UnicodeString = DllStructGetData($Buffer, 1)

I'm guessing that StringLeft is there to prevent some kind of overflow. Seems to be working fine without it. Just wanted to make sure that I'm not going to be creating some problem by modifying it.

Share this post


Link to post
Share on other sites



I am not sure if this is the same, but here is function to convert UTF8 to Ansi:

Func _UTF8ToAnsi($sUTF8)
    Local $iLen = StringLen($sUTF8)
    Local $stBuf = DllStructCreate("byte[" & $iLen * 2 & "];byte[2]")
    
    Local $aRet = DllCall("Kernel32.dll", "int", "MultiByteToWideChar", _
        "int", 65001, "int", 0, _
        "str", $sUTF8, "int", -1, _
        "ptr", DllStructGetPtr($stBuf), "int", $iLen * 2 + 2)
    
    Local $stOut = DllStructCreate("char[" & $iLen & "];char")
    
    $aRet = DllCall("kernel32.dll", "int", "WideCharToMultiByte", _
        "int", 0, "int", 0, _
        "ptr", DllStructGetPtr($stBuf), "int", -1, _
        "ptr", DllStructGetPtr($stOut), "int", $iLen + 1, _
        "int", 0, "int", 0)
    
    Return DllStructGetData($stOut, 1)
EndFunc

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

Not really the same. I just needed to know if my function modification will cause any adverse effects.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Not really the same. I just needed to know if my function modification will cause any adverse effects.

Did you ask the original author?

Edit:

How many chars is it not putting in that you expect it to?

I would have suspected it to be maybe 1?

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

I couldn't remember who the original author was. I'm pretty sure this code was given to me by you or maybe gary. Was hoping the author would stumble upon this post.

It seems to trim off a different number of characters based on the length of the string. Right now it's trimming off 15 characters of a 29 character string.

Share this post


Link to post
Share on other sites

I couldn't remember who the original author was. I'm pretty sure this code was given to me by you or maybe gary. Was hoping the author would stumble upon this post.

It seems to trim off a different number of characters based on the length of the string. Right now it's trimming off 15 characters of a 29 character string.

Makes no sense to me that the String* function is even in there at all. I don't see an issue with removing it and leaving it as you have it.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Ok. Great. I'll leave the original line there commented out in case the author replies with some clarification to the contrary. Thanks smoke.

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