2 messages in net.java.dev.jna.usersRe: [jna-users] WIN32_FIND_DATA mapping
FromSent OnAttachments
jean-michel TSep 11, 2007 7:42 am 
Timothy WallSep 11, 2007 9:21 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [jna-users] WIN32_FIND_DATA mappingActions...
From:Timothy Wall (twal@dev.java.net)
Date:Sep 11, 2007 9:21:40 am
List:net.java.dev.jna.users

On Sep 11, 2007, at 10:42 AM, jean-michel T wrote:

My problem might come from my Structure WIN32_FIND_DATA described on the msdn like the following:

typedef struct _WIN32_FIND_DATA { DWORD dwFileAttributes; FILETIME ftCreationTime; FILETIME ftLastAccessTime; FILETIME ftLastWriteTime; DWORD nFileSizeHigh; DWORD nFileSizeLow; DWORD dwReserved0; DWORD dwReserved1; TCHAR cFileName[MAX_PATH]; TCHAR cAlternateFileName[14]; } WIN32_FIND_DATA, *PWIN32_FIND_DATA, *LPWIN32_FIND_DATA;

What I coded is :

For the Structure: ---- public static class WIN32_FIND_DATA extends Structure {

public int dwFileAttributes; public long ftCreationTime; public long ftLastAccessTime; public long ftLastWriteTime;

Technically, FILETIME is a structure containing two 32-bit values, but this definition should result in the same size/alignment.

public int nFileSizeHigh; public int nFileSizeLow; public int dwReserved0; public int dwReserved1; public String cFileName; public String cAlternateFileName;

These last two are not instances of type "char *", but arrays of TCHAR. While in pointers and arrays are interchangeable as function arguments, they mean different things within a struct definition. "char *" takes up the size of a pointer, while an array of "char" takes up the size of the array. You will need to redefine them as byte[] or char[] (depending on whether you're using ASCII or UNICODE) and initialize them to the proper size, e.g.

public char[] cFileName = new char[MAX_PATH]; public char[] cAlternateFileName = new char[14];

Then you can use Native.toString(char[]) to convert the values back to a Java String.