Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. how to specify the handle for findfirstfile, etc?

how to specify the handle for findfirstfile, etc?

Scheduled Pinned Locked Moved C#
csharptutorialquestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Segal
    wrote on last edited by
    #1

    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);

    S L 2 Replies Last reply
    0
    • S Segal

      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);

      S Offline
      S Offline
      Stephane Rodriguez
      wrote on last edited by
      #2

      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.

      A 1 Reply Last reply
      0
      • S Stephane Rodriguez

        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.

        A Offline
        A Offline
        Anonymous
        wrote on last edited by
        #3

        well, still encounter the same problem.

        S 1 Reply Last reply
        0
        • A Anonymous

          well, still encounter the same problem.

          S Offline
          S Offline
          Stephane Rodriguez
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • S Segal

            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);

            L Offline
            L Offline
            leppie
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups