all groups > visual studio .net general > january 2007 >
You're in the

visual studio .net general

group:

FileStream was asked to open a device that was not a file. For sup


FileStream was asked to open a device that was not a file. For sup thejamie
1/30/2007 8:42:02 AM
visual studio .net general:
Can't figure this one out.

"FileStream was asked to open a device that was not a file. For support for
devices like 'com1:' or 'lpt1:', call CreateFile, then use the FileStream
constructors that take an OS handle as an IntPtr."
--
Regards,
"Stream does not support seeking." thejamie
1/31/2007 12:15:01 PM
I have added code because there is a way around the IntPtr but for now, I am
unable to get this code going although I feel it is very close to working.
Error is "Stream does not support seeking."

To get the filestream with the handle I pass an IntPtr (hport) to a
sub-routine:

Private Function PrintStream(ByVal hPortP As IntPtr, ByVal printername
As String) As FileStream

Dim SA As SECURITY_ATTRIBUTES
Dim outFile As FileStream

LPTPORT = "LPT1"

'Create FileStream using Handle

hPort = CreateFile(LPTPORT, GENERIC_WRITE, FILE_SHARE_WRITE, SA,
OPEN_EXISTING, 0, 0)

'convert Integer to IntPtr

hPortP = New IntPtr(hPort)
outFile = New FileStream(hPortP, FileAccess.Write, False)
PrintStream = outFile

End Function

Here is where I have the problem:

'initialize the file
dim strFileLocation = My.Application.Info.DirectoryPath &
"\" & My.Application.Info.AssemblyName & ".ini"

FileOpen(1, strFileLocation, OpenMode.Input)
FileClose(1)

Dim hport As IntPtr
Dim filestream As FileStream =
PrintStream(hport,ZebPrtrPath)
Dim fileWriter As New StreamWriter(filestream)
fileWriter.BaseStream.Seek(0, SeekOrigin.End)
fileWriter.WriteLine(mstrLabelInfo)
fileWriter.Close()

--
Regards,
Jamie


[quoted text, click to view]
AddThis Social Bookmark Button