|
-
August 2nd, 2011, 10:40 AM
#1
SafeFileHandle equivalent
I have a class library written in VB9, and I need to convert it to .NET Compact Framework 2.0.
I have worked through a good portion of the issues already, but cannot seem to find a workaround for using something similar to SafeFileHandle in CF.
Here is the code:
Code:
Public Sub New(ByVal DevicePath As String)
Try
' open a read/write handle to our device using the DevicePath returned
Dim Handle As New Microsoft.Win32.SafeHandles.SafeFileHandle(CreateFile(DevicePath, FileAccess.ReadWrite, FileShare.ReadWrite, IntPtr.Zero, FileMode.Open, EFileAttributes.Overlapped, IntPtr.Zero), True)
If Not Handle.IsInvalid Then
_Stream = New FileStream(Handle, FileAccess.ReadWrite, 8, True)
_Attributes.Size = Marshal.SizeOf(_Attributes)
If Interop.HidD_GetAttributes(_Stream.SafeFileHandle.DangerousGetHandle, _Attributes) Then
_DevicePath = DevicePath
DeviceSetup()
Else
Throw New ApplicationException(String.Format("Could not get attributes for device '{0}': {1}", DevicePath, GetLastWin32Error.Message))
End If
Else
Throw New ApplicationException("Cannot open specified device: " & GetLastWin32Error.Message)
End If
Catch ex As ApplicationException
Throw
Catch ex As Exception
Throw New ApplicationException(String.Format("Could not access device '{0}': {1}", DevicePath, ex.Message))
End Try
End Sub
SafeFileHandle is not supported under the Compact Framework, so I need to come up with some way to work around that problem while keeping the functionality of the program intact.
Ideally someone will tell me about an equivalent to SafeFileHandle and this will be a simple fix and stupid question, but I am not getting my hopes up.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|