Questions tagged [safefilehandle]

12 questions
6
votes
2 answers

C# WinUSB Can't Call CloseHandle on Interface

I am trying to release a handle to the USB interface with CloseHandle. The exception I get is: System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception. at …
Christian Findlay
  • 6,770
  • 5
  • 51
  • 103
4
votes
1 answer

FileStream and Asynchronous I/O with a device

I'm having some problems writing to a FileStream writing to a SafeFileHandle, this file is used to write data to a HID device. I'll post snippets of the code since these occur in several different objects. This is the handle creation code: HidHandle…
4
votes
2 answers

CreateFile in Kernel32.dll returns an invalid handle

I'm trying to create a safe file handle for "C:" using the CreateFile method of kernel32.dll which always returns me an invalid handle. Any help on what am i doing wrong here?"C: CreateFile( lpFileName: "C:", dwDesiredAccess:…
4
votes
1 answer

Does FileStream.SafeFileHandle *really* set the current stream position to 0?

According to the MSDN documentation for FileStream.SafeFileHandle: The SafeFileHandle property automatically flushes the stream and sets the current stream position to 0. This allows the file to be moved or the stream position to be reset by…
Matthew Watson
  • 104,400
  • 10
  • 158
  • 276
2
votes
1 answer

What is SafeFileHandle in C# and when should I use it?

While I am still learning System.IO, in File Stream class 's constructors, I found that there are overloaded constructors with the type named SafeFileHandle, I tried to search on the internet and the MSDN Documention, but I can't understand…
Salo7ty
  • 475
  • 5
  • 18
1
vote
1 answer

Are there any benefits for using SafeFileHandle with FileStream constructor

I read a lot about SafeFileHandle and from what I've seen I think I don't have to use it or it doesn't have any benefits to use it in FileStream because it is closed by first object of file stream handled it and I can't use it in another…
Salo7ty
  • 475
  • 5
  • 18
0
votes
1 answer

Does class that have SafeFileHandle field should implement Finalizer?

I have the following class in .NetCore console application. This class has FileStream and SafeFileHandle fields. I am using pInvoke to create file and assign the result to SafeFileHandle instance. Does this class should have Finalizer…
Yaniv daye
  • 73
  • 7
0
votes
1 answer

Can i re-open a handle after FileStream close it in c#?

i want to know if can i re-open a handle after FileStream close it ?? this is mycode static void Main(string[] args) { string path = "Hello"; SafeFileHandle handle = File.Open(path, FileMode.OpenOrCreate).SafeFileHandle; …
Salo7ty
  • 475
  • 5
  • 18
0
votes
0 answers

CLR GC thread behavior: SafeFileHandle unexpectedly finalized

We recently hit some issues that may be related to the GC behavior of CLR. The problem I encountered is as follows: We have a long running stress testing application written in C# that keeps opening file handles on a remote SMB file share (which is…
0
votes
1 answer

CreateFile() Works in Windows XP but fails in Windows 7 return Handle Invalid

While trying to create a handler using CreateFile(), even when executing the application as administrator, I get the following error message: ‘The system could not find the specified file. (Exception from HRESULT: 0x80070002)":Nothing.’ Here is a…
msantiago
  • 346
  • 2
  • 4
  • 14
0
votes
0 answers

SafeFileHandle equivalent in windows store app

I have a code written as Windows desktop application. I want to convert it to windows storeapp. However, I could not found equivalent of SafeFileHandle. Here is the code. using Microsoft.Win32.Safehandles; using System; using System.IO; using…
-1
votes
1 answer

Using perl __DATA__ assign its value to variable

I am trying to use the filehandle DATA in a script, assign the values to a variable, and when it prints it just prints and empty string. #!/usr/bin/perl use strict; use warnings; use Data::Dumper qw(Dumper); my $str = ; print "$str\n"…
capser
  • 2,442
  • 5
  • 42
  • 74