The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: oex on March 30, 2010, 11:54:43 PM

Title: FileSystem parse
Post by: oex on March 30, 2010, 11:54:43 PM
I am browsing the filesystem with my app and it gets to a folder named in Chinese '政治清明' findnextfile returns '????' and it fails.... how do I fix this?

???? are wildcard characters but:

a) findfirstfile returns INVALID_HANDLE_VALUE when I pass the folder name ie c:\????\* wildcards so I cant view folder contents
b) This is not very usefull if I want the folder name
Title: Re: FileSystem parse
Post by: joemc on March 31, 2010, 12:56:00 AM
forgive me for not reading the entire code, have you tried FindFirstFileW ?
Title: Re: FileSystem parse
Post by: oex on March 31, 2010, 02:40:58 PM
ok findfirstfileW will work....

OK simpler question then.... How do I pass a unicode string? Currently I'm calling the function with chr$("c:\path\*")

EDIT: OK found it.... \masm32\macros\umacros.asm :lol who would have thought that's what the other macros file I hadnt used yet was for
Title: Re: FileSystem parse
Post by: oex on March 31, 2010, 11:48:17 PM
Doh! This isnt as easy as I expected.... I have used WSTR to create a string 'c:\*'

Printed it in a MessageBoxW to make sure it works (and it does)

Then fed it to FindFirstFileW function which *of course* errors and curses at me....

.data
WSTR    DriveX, "c:\*"

.code
invoke  MessageBoxW,0,ADDR DriveX,ADDR DriveX,MB_OK

LOCAL wfd:WIN32_FIND_DATA

invoke FindFirstFileW,ADDR DriveX,ADDR wfd
Title: Re: FileSystem parse
Post by: Gunner on March 31, 2010, 11:53:03 PM
If you are using the unicode apis, then make sure you are using the unicode structures where appropriate:

Requirements
Minimum supported client Windows 2000 Professional
Minimum supported server Windows 2000 Server
Header WinBase.h (include Windows.h)
Unicode and ANSI names WIN32_FIND_DATAW (Unicode) and WIN32_FIND_DATAA (ANSI)
Title: Re: FileSystem parse
Post by: oex on March 31, 2010, 11:55:40 PM
Nice 1 ty, just did this in between posts and came back to find out if I was cheating :lol

WIN32_FIND_DATA2 STRUCT
  dwFileAttributes      DWORD      ?
  ftCreationTime        FILETIME <>
  ftLastAccessTime      FILETIME <>
  ftLastWriteTime       FILETIME <>
  nFileSizeHigh         DWORD      ?
  nFileSizeLow          DWORD      ?
  dwReserved0           DWORD      ?
  dwReserved1           DWORD      ?
  cFileName             BYTE MAX_PATH*2 dup(?) <------
  cAlternate            BYTE 14 dup(?)
WIN32_FIND_DATA2 ENDS


Will use WIN32_FIND_DATAW instead

As one might expect these unicode symbols are all foreign to me :lol
Title: Re: FileSystem parse
Post by: oex on April 01, 2010, 12:23:18 AM
@Hutch: WIN32_FIND_DATAW doesnt appear to be in windows.inc

I'm guessing it is:

WIN32_FIND_DATAW STRUCT
  dwFileAttributes      DWORD      ?
  ftCreationTime        FILETIME <>
  ftLastAccessTime      FILETIME <>
  ftLastWriteTime       FILETIME <>
  nFileSizeHigh         DWORD      ?
  nFileSizeLow          DWORD      ?
  dwReserved0           DWORD      ?
  dwReserved1           DWORD      ?
  cFileName             WORD MAX_PATH dup(?)
  cAlternate            BYTE 14 dup(?) <---- Not sure what happens here?
WIN32_FIND_DATAW ENDS

Cant find the structure on the M$ website

http://www.masm32.com/board/index.php?topic=12654.msg99153#msg99153
Title: Re: FileSystem parse
Post by: Gunner on April 01, 2010, 01:37:31 AM
this is from the header files:
typedef struct _WIN32_FIND_DATAA {
    DWORD dwFileAttributes;
    FILETIME ftCreationTime;
    FILETIME ftLastAccessTime;
    FILETIME ftLastWriteTime;
    DWORD nFileSizeHigh;
    DWORD nFileSizeLow;
    DWORD dwReserved0;
    DWORD dwReserved1;
    CHAR   cFileName[ MAX_PATH ];
    CHAR   cAlternateFileName[ 14 ];
#ifdef _MAC
    DWORD dwFileType;
    DWORD dwCreatorType;
    WORD  wFinderFlags;
#endif
} WIN32_FIND_DATAA, *PWIN32_FIND_DATAA, *LPWIN32_FIND_DATAA;
typedef struct _WIN32_FIND_DATAW {
    DWORD dwFileAttributes;
    FILETIME ftCreationTime;
    FILETIME ftLastAccessTime;
    FILETIME ftLastWriteTime;
    DWORD nFileSizeHigh;
    DWORD nFileSizeLow;
    DWORD dwReserved0;
    DWORD dwReserved1;
    WCHAR  cFileName[ MAX_PATH ];
    WCHAR  cAlternateFileName[ 14 ];
Title: Re: FileSystem parse
Post by: oex on April 01, 2010, 12:53:07 PM
Awesome ty :)