hi,
My code works but i am missing the first 2 characters of file name.
Any idea why???? - 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;
-
using System.Threading;
-
-
-
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)
-
{
-
-
rfidTagHandle = Win32Methods.FindFirstFile("\\*.*", out FindFileData);
-
//"\\RFID\\[.]"
-
if (rfidTagHandle == Win32Methods.INVALID_HANDLE_VALUE)
-
{
-
MessageBox.Show("FindFirstFile failed");
-
-
}
-
else
-
{
-
-
//Byte[] fileName =FindFileData.cFileName;
-
//string filen = System.Text.UnicodeEncoding.Unicode.GetString(fileName, 0, fileName.Length);
-
//StringBuilder cb = new StringBuilder(256);
-
//cb = FindFileData.cFileName;
-
string filen = FindFileData.cFileName;
-
textBox1.Text = textBox1.Text + filen + "\r\n";
-
}
-
-
while (Win32Methods.FindNextFile(rfidTagHandle, out FindFileData) != false)
-
{
-
//Byte[] fileName = FindFileData.cFileName;
-
//string filen = System.Text.UnicodeEncoding.Unicode.GetString(fileName, 0, fileName.Length);
-
//StringBuilder cb = new StringBuilder(256);
-
//cb = FindFileData.cFileName;
-
string filen = FindFileData.cFileName;
-
textBox1.Text = textBox1.Text + filen + "\r\n";
-
-
-
}
-
MessageBox.Show("FindnextFile failed");
-
Win32Methods.FindClose(rfidTagHandle);
-
-
}
-
-
-
}
-
-
public class Win32Methods
-
{
-
-
public const int INVALID_HANDLE_VALUE = -1;
-
//, CharSet = CharSet.Unicode
-
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
-
public struct WIN32_FIND_DATA
-
{
-
public uint dwFileAttributes;
-
public FILETIME ftCreationTime;
-
public FILETIME ftLastAccessTime;
-
public FILETIME ftLastWriteTime;
-
public uint nFileSizeHigh;
-
public uint nFileSizeLow;
-
public uint dwReserved0;
-
public uint dwReserved1;
-
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
-
public string cFileName;
-
//[MarshalAs(UnmanagedType.LPStr)]
-
//public StringBuilder cFileName;
-
//[MarshalAs(UnmanagedType.ByValArray, SizeConst = 260)]
-
//public Byte[] cFileName;
-
//[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
-
//public string cAlternateFileName;
-
-
};
-
-
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
-
public struct FILETIME
-
{
-
public uint dwLowDateTime;
-
public uint dwHighDateTime;
-
};
-
-
//Findfirstfile
-
[DllImport("coredll.dll", CharSet = CharSet.Auto,SetLastError = true)]
-
public static extern int FindFirstFile(string szSearchFile,out WIN32_FIND_DATA lpFindFileData);
-
-
//FindNextFile
-
[DllImport("coredll.dll",CharSet = CharSet.Auto, SetLastError = true)]
-
[return: MarshalAs(UnmanagedType.Bool)]
-
public static extern bool FindNextFile(int hFindFile,out WIN32_FIND_DATA lpFindFileData);
-
//Findclose
-
[DllImport("coredll.dll",CharSet = CharSet.Auto, SetLastError = true)]
-
[return: MarshalAs(UnmanagedType.Bool)]
-
public static extern bool FindClose(int hFindFile);
-
}
-
-
}
3 1998
Why are you doing all of that with unmanaged code?
What was wrong with: -
Directory.GetFiles(Path, pattern);
-
???
System.IO is still in CF2
actually I have a handheld reader which has a file system and starts reading rfid tags using the command findfirst file
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?
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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 =...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
|
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...
| |