how to specify the handle for findfirstfile, etc?
-
I used the wrapper to make my C# program to recognize the datatype win32_find_Data, however, the compiler doesn't accept the IntPtr as the return type for function "Findfirstfile", what's the solution for this? Following is the sample code: struct FILETIME { int dwLowDateTime; int dwHighDateTime; } struct WIN32_FIND_DATA { int dwFileAttributes; FILETIME ftCreationTime; FILETIME ftLastAccessTime; FILETIME ftLastWriteTime; int nFileSizeHigh; int nFileSizeLow; int dwReserved0; int dwReserved1; string cFileName; //mite need marshalling, TCHAR size = MAX_PATH??? string cAlternateFileName; //mite need marshalling, TCHAR size = 14 } [DllImport("kernel32.dll")] static extern IntPtr FindFirstFile( IntPtr lpfilename, ref WIN32_FIND_DATA findfiledata);
-
I used the wrapper to make my C# program to recognize the datatype win32_find_Data, however, the compiler doesn't accept the IntPtr as the return type for function "Findfirstfile", what's the solution for this? Following is the sample code: struct FILETIME { int dwLowDateTime; int dwHighDateTime; } struct WIN32_FIND_DATA { int dwFileAttributes; FILETIME ftCreationTime; FILETIME ftLastAccessTime; FILETIME ftLastWriteTime; int nFileSizeHigh; int nFileSizeLow; int dwReserved0; int dwReserved1; string cFileName; //mite need marshalling, TCHAR size = MAX_PATH??? string cAlternateFileName; //mite need marshalling, TCHAR size = 14 } [DllImport("kernel32.dll")] static extern IntPtr FindFirstFile( IntPtr lpfilename, ref WIN32_FIND_DATA findfiledata);
Declaration :
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
public struct FILETIME
{
public Int32 dwLowDateTime;
public Int32 dwHighDateTime;
}[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
public struct WIN32_FIND_DATA
{
public Int32 dwFileAttributes;
public FILETIME ftCreationTime;
public FILETIME ftLastAccessTime;
public FILETIME ftLastWriteTime;
public Int32 nFileSizeHigh;
public Int32 nFileSizeLow;
public Int32 dwReserved0;
public Int32 dwReserved1;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst= 260)]public string cFileName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst= 14)]public string cAlternateFileName;
}[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr FindFirstFile( string lpfilename,
out WIN32_FIND_DATA findfiledata);Usage :
String s = @"*.js";
WIN32Wrapper.WIN32_FIND_DATA findfiledata;
IntPtr handle = WIN32Wrapper.FindFirstFile( s, out findfiledata);
And I swallow a small raisin.
-
Declaration :
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
public struct FILETIME
{
public Int32 dwLowDateTime;
public Int32 dwHighDateTime;
}[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
public struct WIN32_FIND_DATA
{
public Int32 dwFileAttributes;
public FILETIME ftCreationTime;
public FILETIME ftLastAccessTime;
public FILETIME ftLastWriteTime;
public Int32 nFileSizeHigh;
public Int32 nFileSizeLow;
public Int32 dwReserved0;
public Int32 dwReserved1;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst= 260)]public string cFileName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst= 14)]public string cAlternateFileName;
}[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr FindFirstFile( string lpfilename,
out WIN32_FIND_DATA findfiledata);Usage :
String s = @"*.js";
WIN32Wrapper.WIN32_FIND_DATA findfiledata;
IntPtr handle = WIN32Wrapper.FindFirstFile( s, out findfiledata);
And I swallow a small raisin.
-
Works fine for me, If you have a problem compiling this code, then the bug is trivial, it is not even a marshalling problem,
And I swallow a small raisin.
-
I used the wrapper to make my C# program to recognize the datatype win32_find_Data, however, the compiler doesn't accept the IntPtr as the return type for function "Findfirstfile", what's the solution for this? Following is the sample code: struct FILETIME { int dwLowDateTime; int dwHighDateTime; } struct WIN32_FIND_DATA { int dwFileAttributes; FILETIME ftCreationTime; FILETIME ftLastAccessTime; FILETIME ftLastWriteTime; int nFileSizeHigh; int nFileSizeLow; int dwReserved0; int dwReserved1; string cFileName; //mite need marshalling, TCHAR size = MAX_PATH??? string cAlternateFileName; //mite need marshalling, TCHAR size = 14 } [DllImport("kernel32.dll")] static extern IntPtr FindFirstFile( IntPtr lpfilename, ref WIN32_FIND_DATA findfiledata);
they have the exact sample on MSDN, look under marshalling :) MYrc : A .NET IRC client with C# Plugin Capabilities. See http://sourceforge.net/projects/myrc for more info. :-D