|
-
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.
-
August 2nd, 2011, 10:51 AM
#2
Re: SafeFileHandle equivalent
Victor Nijegorodov
-
August 2nd, 2011, 10:57 AM
#3
Re: SafeFileHandle equivalent
I need something that will work in Compact Framework though.
I get: Type 'Microsoft.Win32.SafeHandles.SafeFileHandle' is not defined.
-
July 11th, 2012, 07:06 AM
#4
Re: SafeFileHandle equivalent
Sorry for digging out old topic, but did you find the answer? I have the same problem now. I got some code for desktop application that is working fine, but when i try to do the same on windows mobile device (motorola mc9090) i need safefilehandle, but there's no such thing...
-
July 11th, 2012, 07:16 AM
#5
Re: SafeFileHandle equivalent
Sorry for digging out old topic, but i have the same problem. I have some code that is working in desktop application but i nedd to do the same in Compact Framework. Did you find solution?
-
July 11th, 2012, 07:48 AM
#6
Re: SafeFileHandle equivalent
I guess, you should ask it in some of the .Net forums, since "Compact Framework" has nothing to do with the native C++/VC++ applications.
Victor Nijegorodov
-
July 11th, 2012, 07:50 AM
#7
Re: SafeFileHandle equivalent
Ok, then i'll try there. Thanks
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
|