473,856 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Missing first 2 charcters of file name in win ce(.net cf 2.0) using findfirstfile

4 New Member

My code works but i am missing the first 2 characters of file name.
Any idea why????

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. using System.Threading;
  12. namespace dummy2
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         int rfidTagHandle;
  17.         Win32Methods.WIN32_FIND_DATA FindFileData;
  21.         public Form1()
  22.         {
  23.             InitializeComponent();
  24.         }
  26.         private void button1_Click(object sender, EventArgs e)
  27.         {
  29.             rfidTagHandle = Win32Methods.FindFirstFile("\\*.*", out FindFileData);
  30.             //"\\RFID\\[.]"
  31.             if (rfidTagHandle == Win32Methods.INVALID_HANDLE_VALUE)
  32.             {
  33.                 MessageBox.Show("FindFirstFile failed");
  35.             }
  36.             else
  37.             {
  39.                 //Byte[] fileName =FindFileData.cFileName;
  40.                 //string filen = System.Text.UnicodeEncoding.Unicode.GetString(fileName, 0, fileName.Length);
  41.                 //StringBuilder cb = new StringBuilder(256);
  42.                 //cb = FindFileData.cFileName;
  43.                 string filen = FindFileData.cFileName;
  44.                 textBox1.Text = textBox1.Text + filen + "\r\n";
  45.             }
  47.             while (Win32Methods.FindNextFile(rfidTagHandle, out FindFileData) != false)
  48.             {
  49.                 //Byte[] fileName = FindFileData.cFileName;
  50.                 //string filen = System.Text.UnicodeEncoding.Unicode.GetString(fileName, 0, fileName.Length);
  51.                 //StringBuilder cb = new StringBuilder(256);
  52.                 //cb = FindFileData.cFileName;
  53.                 string filen = FindFileData.cFileName;
  54.                 textBox1.Text = textBox1.Text + filen + "\r\n";
  57.             }
  58.             MessageBox.Show("FindnextFile failed");
  59.             Win32Methods.FindClose(rfidTagHandle);
  61.         }
  64.     }
  66.     public class Win32Methods
  67.     {
  69.         public const int INVALID_HANDLE_VALUE = -1;
  70.         //, CharSet = CharSet.Unicode
  71.         [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
  72.         public struct WIN32_FIND_DATA
  73.         {
  74.             public uint dwFileAttributes;
  75.             public FILETIME ftCreationTime;
  76.             public FILETIME ftLastAccessTime;
  77.             public FILETIME ftLastWriteTime;
  78.             public uint nFileSizeHigh;
  79.             public uint nFileSizeLow;
  80.             public uint dwReserved0;
  81.             public uint dwReserved1;
  82.             [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
  83.             public string cFileName;
  84.             //[MarshalAs(UnmanagedType.LPStr)]
  85.             //public StringBuilder cFileName;
  86.             //[MarshalAs(UnmanagedType.ByValArray, SizeConst = 260)]
  87.             //public Byte[] cFileName;
  88.             //[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
  89.             //public string cAlternateFileName;
  91.         };
  93.         [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
  94.         public struct FILETIME
  95.         {
  96.             public uint dwLowDateTime;
  97.             public uint dwHighDateTime;
  98.         };
  100.         //Findfirstfile
  101.         [DllImport("coredll.dll", CharSet = CharSet.Auto,SetLastError = true)]
  102.         public static extern int FindFirstFile(string szSearchFile,out WIN32_FIND_DATA lpFindFileData);
  104.         //FindNextFile
  105.         [DllImport("coredll.dll",CharSet = CharSet.Auto, SetLastError = true)]
  106.         [return: MarshalAs(UnmanagedType.Bool)]
  107.         public static extern bool FindNextFile(int hFindFile,out WIN32_FIND_DATA lpFindFileData);
  108.         //Findclose
  109.         [DllImport("coredll.dll",CharSet = CharSet.Auto, SetLastError = true)]
  110.         [return: MarshalAs(UnmanagedType.Bool)]
  111.         public static extern bool FindClose(int hFindFile);
  112.     }
  114. }
Nov 28 '07 #1
3 2025
7,872 Recognized Expert Expert
Why are you doing all of that with unmanaged code?
What was wrong with:
Expand|Select|Wrap|Line Numbers
  1. Directory.GetFiles(Path, pattern);
System.IO is still in CF2
Nov 28 '07 #2
4 New Member
actually I have a handheld reader which has a file system and starts reading rfid tags using the command findfirst file
Nov 29 '07 #3
7,872 Recognized Expert Expert
EDIT: WOW I can't believe I missed that.
You're using a Unicode conversion, it's probably treating the first two characters as the byte-order mark.
Try using the ASCII encoding and see what you get?
Nov 29 '07 #4

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

Similar topics

by: Corepaul | last post by:
Missing Help Files When I enter "recordset" as the keyword and search the Visual Basic Help index, I get many topics of interest in the resulting list. But there isn't any information available from clicking on many of the available topics (mostly methods but some properties are also unavailable). This same problem occurs with many, if not most, keywords. Is there any way I can activate these "missing" help topics? HELP!
by: tom | last post by:
Hello, I want to know if FindFirstFile() can do more as I expect. FindFirstFile() can take the arguement of "*" or "?", for example, FindFirstFile("result.*.txt", &FileData); I want to get files result_12.txt or result10.txt only, Could it be possible that it allows "||"?
by: Paulo Eduardo | last post by:
Hi, all! We are devleping one app that will use disk access with FindFirstFile and FindNextFile for it. Can someone expose me how works FindFirstFile and FindNextFile in disk access? Does the findFirstfile read all files of disk and put in physical memory , and FindFirstFile read files from memory? Can someone help us? Thanks in advance.
by: tshad | last post by:
I am trying to set up a reusable library (business component) that I can use in a bunch of my pages. I built the file and it almost compiles, but I am not sure what I am missing. The vbc command and results are: ************************************************************************ C:\Inetpub\wwwroot\Development>vbc /t:library emailClass.vb
by: Jason | last post by:
I need to open a file for reading, but I only know part of it's name. The file I want to read is in the format of xxx-yyyy-zzz.EXT The last three digits of the file name are different on each pc, for example PC7 has xxx-yyyy-zz1.ext PC5 has xxx-yyyy-zz2.ext PC3 has xxx-yyyy-zz8.ext
by: Andrew | last post by:
Hello, I am trying to find a way to take the contents of a directory and write it into a file. I have a directory that has several hundred text files, and I want to create a file containing all of the names of those files. I can get the contents of the directory onto the screen using system("dir"); But I have not been able to get this data into a file. I understand that stdout is a pointer to a file, and so I should be able to open and...
by: im2cre8iv | last post by:
Here is my code where I am receiving the error: #include <fstream> #include "BinaryTree.h" using namespace std; Node* BinaryTree::MakeTree(ifstream& infile) { char name; infile>>name;
by: William Krick | last post by:
Given these two code snippets, the first generates errors, the second doesn't... // generates errors $tboard = $context; $tboard = empty($tboard)?'':' - '.$tboard; $ttopic = $context; $ttopic = empty($ttopic)?'':' - '.$ttopic; if (! ereg($context, $context)) $context = $context.$tboard.
by: Monty | last post by:
Hi All, I am having a problem with leading zeros being stripped from fields in a CSV file when I bring them in using Jet/OleDB. In VB.Net/VS 2008, I am accessing a CSV file like so: sSQL = "SELECT * FROM " sConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _ Microsoft.VisualBasic.FileIO.FileSystem.GetParentPath(msFile) & _
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.