Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Invalid Handle filestream vb2005 on 64 bit machine

Status
Not open for further replies.

zarkon4

MIS
Dec 16, 2003
641
US
I have some code that runs great on 32 bit systems, but when it is running on a 64 bit system I get an error of Invalid Handle.
Here is the code

Dim SA As SECURITY_ATTRIBUTES
Dim retval As Int32
Dim intPort As Int32
Dim intPortPointer As IntPtr
Dim fsOutFile As FileStream
Dim handle As SafeHandle

intPort = CreateFile(strPrinter, GENERIC_WRITE, FILE_SHARE_WRITE, SA, OPEN_EXISTING, 0, 0)

intPortPointer = New IntPtr(intPort) 'convert Integer to IntPtr

handle = New SafeFileHandle(intPortPointer, True)

fsOutFile = New FileStream(handle, FileAccess.Write) 'Create FileStream using Handle

Dim fileWriter As New StreamWriter(fsOutFile)

fileWriter.Write("some stuff")

fileWriter.Flush()
fileWriter.Close()
fsOutFile.Close()

retval = CloseHandle(intPort)


any help is greatly appreciated
 
I didn't really figure it out but I had to set the Compile advanced options target cpu to use x86 only....problem went away. I still would like to get this working in 64 bit and am still looking for a solution.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top