471,119 Members | 1,410 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,119 software developers and data experts.

C# WinCE-App: problem in marshal findfirstfile in c# win ce device

4
hello everybody

I am having a very wierd problem.i am developing a win ce applicationin which I am marshalling win ap function findfirstfile and findnextfile in c# .My problem is it reads the file name but it misses the first 2 characters of each file name.I have no idea why .Please help.
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Runtime.InteropServices;
  9.  
  10.  
  11. namespace dummy2
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         int rfidTagHandle;
  16.         Win32Methods.WIN32_FIND_DATA FindFileData;
  17.  
  18.  
  19.         public Form1()
  20.         {
  21.             InitializeComponent();
  22.         }
  23.  
  24.         private void button1_Click(object sender, EventArgs e)
  25.         {
  26.             //for (int i = 0; i <= 2; i++)
  27.             //{
  28.             rfidTagHandle = Win32Methods.FindFirstFile("*.*", out FindFileData);
  29.                 //"\\RFID\\[.]"
  30.                 if (rfidTagHandle == Win32Methods.INVALID_HANDLE_VALUE)
  31.                 {
  32.                     MessageBox.Show("FindFirstFile failed");
  33.  
  34.                 }
  35.                 else
  36.                 {
  37.  
  38.                     String fileName = FindFileData.cFileName;
  39.                     //MessageBox.Show("File name length is" + FindFileData.cFileName.Length.ToString());
  40.                     //textBox1.Text = "Application" + "\r\n";
  41.                     textBox1.Text = textBox1.Text + fileName + "\r\n";
  42.                 }
  43.  
  44.                 while (Win32Methods.FindNextFile(rfidTagHandle, out FindFileData) != false)
  45.                 {
  46.                     String fileName = FindFileData.cFileName;
  47.                     textBox1.Text = textBox1.Text + fileName + "\r\n";
  48.                     //MessageBox.Show("next File name is" + fileName);
  49.                     //listView1.Items.Add(fileName); 
  50.  
  51.                 }
  52.                 MessageBox.Show("FindnextFile failed");
  53.                 Win32Methods.FindClose(rfidTagHandle);
  54.            // }
  55.         }
  56.     }
  57.  
  58.     public class Win32Methods
  59.     {
  60.  
  61.         public const int INVALID_HANDLE_VALUE = -1;
  62.  
  63.         [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
  64.         public struct WIN32_FIND_DATA
  65.         {
  66.             public int dwFileAttributes;
  67.             public FILETIME ftCreationTime;
  68.             public FILETIME ftLastAccessTime;
  69.             public FILETIME ftLastWriteTime;
  70.             public int nFileSizeHigh;
  71.             public int nFileSizeLow;
  72.             public int dwReserved0;
  73.             public int dwReserved1;
  74.             [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
  75.             public string cFileName;
  76.             //[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
  77.             //public string cAlternateFileName;
  78.  
  79.         };
  80.  
  81.         [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
  82.         public struct FILETIME
  83.         {
  84.             public uint dwLowDateTime;
  85.             public uint dwHighDateTime;
  86.         };
  87.  
  88.         //Findfirstfile
  89.         [DllImport("coredll", CharSet = CharSet.Unicode, SetLastError = true)]
  90.         public static extern int FindFirstFile(string szSearchFile, out WIN32_FIND_DATA lpFindFileData);
  91.  
  92.         //FindNextFile
  93.         [DllImport("coredll", CharSet = CharSet.Unicode, SetLastError = true)]
  94.         [return: MarshalAs(UnmanagedType.Bool)]
  95.         public static extern bool FindNextFile(int hFindFile,out WIN32_FIND_DATA lpFindFileData);
  96.         //Findclose
  97.         [DllImport("coredll", CharSet = CharSet.Unicode)]
  98.         [return: MarshalAs(UnmanagedType.Bool)]
  99.         public static extern bool FindClose(int hFindFile);
  100.     }
  101.  
  102. }
  103.  
thanks in advance
Nov 23 '07 #1
1 3435
gudiya
4
I also want to mention the same code when i make as normal c# windows application(not pocket pc) it works.Please help.It's urgent
Nov 27 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by jason | last post: by
1 post views Thread by chanmy8 | last post: by
1 post views Thread by Monica Cummings | last post: by
1 post views Thread by Frederic_BD | last post: by
2 posts views Thread by parth_mca | last post: by
2 posts views Thread by bokiteam | last post: by
3 posts views Thread by pcm | last post: by
1 post views Thread by TheSebaster | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.