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
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using System.Runtime.InteropServices;
- namespace dummy2
- {
- public partial class Form1 : Form
- {
- int rfidTagHandle;
- Win32Methods.WIN32_FIND_DATA FindFileData;
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- //for (int i = 0; i <= 2; i++)
- //{
- rfidTagHandle = Win32Methods.FindFirstFile("*.*", out FindFileData);
- //"\\RFID\\[.]"
- if (rfidTagHandle == Win32Methods.INVALID_HANDLE_VALUE)
- {
- MessageBox.Show("FindFirstFile failed");
- }
- else
- {
- String fileName = FindFileData.cFileName;
- //MessageBox.Show("File name length is" + FindFileData.cFileName.Length.ToString());
- //textBox1.Text = "Application" + "\r\n";
- textBox1.Text = textBox1.Text + fileName + "\r\n";
- }
- while (Win32Methods.FindNextFile(rfidTagHandle, out FindFileData) != false)
- {
- String fileName = FindFileData.cFileName;
- textBox1.Text = textBox1.Text + fileName + "\r\n";
- //MessageBox.Show("next File name is" + fileName);
- //listView1.Items.Add(fileName);
- }
- MessageBox.Show("FindnextFile failed");
- Win32Methods.FindClose(rfidTagHandle);
- // }
- }
- }
- public class Win32Methods
- {
- public const int INVALID_HANDLE_VALUE = -1;
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
- public struct WIN32_FIND_DATA
- {
- public int dwFileAttributes;
- public FILETIME ftCreationTime;
- public FILETIME ftLastAccessTime;
- public FILETIME ftLastWriteTime;
- public int nFileSizeHigh;
- public int nFileSizeLow;
- public int dwReserved0;
- public int dwReserved1;
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
- public string cFileName;
- //[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
- //public string cAlternateFileName;
- };
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
- public struct FILETIME
- {
- public uint dwLowDateTime;
- public uint dwHighDateTime;
- };
- //Findfirstfile
- [DllImport("coredll", CharSet = CharSet.Unicode, SetLastError = true)]
- public static extern int FindFirstFile(string szSearchFile, out WIN32_FIND_DATA lpFindFileData);
- //FindNextFile
- [DllImport("coredll", CharSet = CharSet.Unicode, SetLastError = true)]
- [return: MarshalAs(UnmanagedType.Bool)]
- public static extern bool FindNextFile(int hFindFile,out WIN32_FIND_DATA lpFindFileData);
- //Findclose
- [DllImport("coredll", CharSet = CharSet.Unicode)]
- [return: MarshalAs(UnmanagedType.Bool)]
- public static extern bool FindClose(int hFindFile);
- }
- }