Sign in to follow this  
Followers 0
goldenix

[solved] How to DllStructCreate(char[UTF8]) ?

12 posts in this topic

#1 ·  Posted (edited)

Hire is the thing, I drop the file into my gui, the problem is that the filepath is returned like this ??????.dat

I found this topic, with Functions for Ascii, Unicode, and UTF8 encoding.

But i dont understand how to use them. Can someone show, how to DllStructCreate in utf8?

I might try myself, but I do not understand how is the filepath string being created. cuz look:

$tDrop = DllStructCreate("char[260]") ; I think that I need to make it in UTF. But this is the first time im doing this so Im not sure.

Those UDFS use this, but in my udf I cant use this cuz I dont have the input string in a first place so this is really confusing me:

Local $BufferSize = StringLen($Utf8String) * 2
    Local $Buffer = DllStructCreate("byte[" & $BufferSize & "]")

Hire is GUi drag & drop function:

GUIRegisterMsg(0x233, "On_WM_DROPFILES")

Func On_WM_DROPFILES($hWnd, $Msg, $wParam, $lParam)
    Local $tDrop, $aRet, $iCount
    ;string buffer for file path
    $tDrop = DllStructCreate("char[260]")
    ;get file count
    $aRet = DllCall("shell32.dll", "int", "DragQueryFile", _
                                            "hwnd", $wParam, _
                                            "uint", -1, _
                                            "ptr", DllStructGetPtr($tDrop), _
                                            "int", DllStructGetSize($tDrop) _
                                            )
    $iCount = $aRet[0]
    ;get file paths
    For $i = 0 To $iCount-1
        $aRet = DllCall("shell32.dll", "int", "DragQueryFile", _
                                                "hwnd", $wParam, _
                                                "uint", $i, _
                                                "ptr", DllStructGetPtr($tDrop), _
                                                "int", DllStructGetSize($tDrop) _
                                                )

        $File = DllStructGetData($tDrop, 1)
        ConsoleWrite($File & @CRLF)
        _lock_file()
    Next
    ;finalize
    DllCall("shell32.dll", "int", "DragFinish", "hwnd", $wParam)
    Return
EndFunc
Edited by goldenix

My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]

Share this post


Link to post
Share on other sites



Geez, that's wrong:

Local $BufferSize = StringLen($Utf8String) * 2
Local $Buffer = DllStructCreate("byte[" & $BufferSize & "]")

StringLen return a length in Unicode characters, while you (or someone else) allocates that many bytes. Knowing that a single Unicode codepoint can need anything from 1 up to 4 bytes in UTF-8 encoding, that is really wrong to do it that way.

Now in your drag&drop function, why are you messing with DllStruct at all? Why not pass a Unicode string directly. I didn't look closely but I believe shell32 is fully Unicode-aware (by now). AutoIt' strings are UTF-16 Unicode already (actually more like UCS-2, but forget that distinction immediately). You probably should pass the string directly and its StringLen() length.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

Geez, that's wrong:

Now in your drag&drop function, why are you messing with DllStruct at all?

Hire is the thing, this drag & drop files into gui UDF, is not written by me. So I have no clue how it works & my knowledge in dlls is rather limited.

Can you make an example to show, how to pass a Unicode string directly please?


My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]

Share this post


Link to post
Share on other sites

The closest I've found is a well writen UDF by Yashied named WinAPIex.au3, where you find the correct interface: _WinAPI_DragQueryFileEx(). Use the search function to locate it and download. Probably search will turn out working examples as well. Anyway, the call used is to DragQueryFileW (Unicode interface).


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

First call is:

DllCall("shell32.dll", "dword", "DragQueryFileW", _
        "handle", $wParam, _
        "dword", -1, _
        "wstr", "", _
        "dword", 32767)

Here you collect $array[0] - total number of files dropped.

The other call(s):

DllCall("shell32.dll", "dword", "DragQueryFileW", _
        "handle", $wParam, _
        "dword", $i, _
        "wstr", "", _
        "dword", 32767)

$array[3] is what you want here.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

Hi Trancexx,

I was wondering if that would work. Generally when a parameter is "Out", it's enough to do like you show (I did so in the SQLite UDF when I had to improve it somehow), leaving DllCall allocate the output result transparently. What made me hesitate is that Yashied' function was making a first call in order to get the wchar buffer size, then setting up a DllStruct to receive the pathname and finally a second call to grab the filename.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

It would work, no worries.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

First call is:

DllCall("shell32.dll", "dword", "DragQueryFileW", _
        "handle", $wParam, _
        "dword", -1, _
        "wstr", "", _
        "dword", 32767)

Here you collect $array[0] - total number of files dropped.

The other call(s):

DllCall("shell32.dll", "dword", "DragQueryFileW", _
        "handle", $wParam, _
        "dword", $i, _
        "wstr", "", _
        "dword", 32767)

$array[3] is what you want here.

Non of this works. All I get is non array variable used error.

So a question, All my tests show, that if I retrieve the filepath with DllStructGetData, its already ????? corrupted. is there anything I can do about it? like convert it to binary before I retrieve it from dll ?

$aRet = DllCall("shell32.dll", "int", "DragQueryFile", _
                                                "hwnd", $wParam, _
                                                "uint", $i, _
                                                "ptr", DllStructGetPtr($tDrop), _
                                                "int", DllStructGetSize($tDrop) _
                                                )
        $File = DllStructGetData($tDrop, 1)
Edited by goldenix

My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]

Share this post


Link to post
Share on other sites

Are you sure you tested the W version? Which error code did you get?

Once data has been "converted" from Unicode to ANSI codepage and if the string had any character outside the current user ANSI codepage, those characters are replaced by the question marks you see, so it's irrecoverable.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

Are you sure you tested the W version? Which error code did you get?

Nop looks like I tested the wrong version after all. I found the right version now. thanx.

and looks like this udfdoes the job.


My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]

Share this post


Link to post
Share on other sites

Non of this works. All I get is non array variable used error.

So a question, All my tests show, that if I retrieve the filepath with DllStructGetData, its already ????? corrupted. is there anything I can do about it? like convert it to binary before I retrieve it from dll ?

$aRet = DllCall("shell32.dll", "int", "DragQueryFile", _
                                                "hwnd", $wParam, _
                                                "uint", $i, _
                                                "ptr", DllStructGetPtr($tDrop), _
                                                "int", DllStructGetSize($tDrop) _
                                                )
        $File = DllStructGetData($tDrop, 1)

That's because you are dumb.

You don't even know what version of AutoIt you run. If your AutoIt is older then say so.

Is it ok if I call you dumb? If not then sorry.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

A person tries to learn a little about dlls, figure out how to extract filepath from a dropped file, but every single example he finds does not explain in detail how its done, its simply works or not. So go figure.

I did not quite understood what he was talking about when he said the W for the first time. So I looked up wrong udf. Its a shame that the UDFS are not categorized. Instead, user needs to start topics & ask :(

Im using AutoIt Version: 3.3.0.0.

Anyway thanx for ur help I appreciate it.


My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]

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