WriteFile() from Module

BlitzMax Forums/BlitzMax Programming/WriteFile() from Module

Nigel Brown(Posted 2005) [#1]
When calling the windows function WriteFile(handle, buffer, size, buffer, 0) from a BMX I am getting the error ERROR_ACCESS_DENIED is this a BUG? seems to work fine when using the same code from Blitz3D! using userlibs


Strict


Extern "win32"

Function GetCommState:Int( handle:Int, DCB:Byte Ptr )
Function SetCommState( handle:Int, DCB:Byte Ptr )

Function BuildCommDCBA:Int( config:Byte Ptr, DCB:Byte Ptr )
Function GetCommTimeouts:Int( handle:Int, Timeouts:Byte Ptr )
Function SetCommTimeouts:Int( handle:Int, Timeouts:Byte Ptr )

Function CreateFileA:Int( filename:Byte Ptr, DesiredAccess:Int, ShareMode:Int, SecurityAttribute:Int, CreationDistribution:Int, FlagsAndAttributes:Int, TemplateFile:Int )
Function CloseHandle:Int( handle:Int )

Function WriteFile:Int( handle:Int, pBuffer:Byte Ptr, NumberOfBytesToWrite:Int, pNumberOfBytesWritten:Byte Ptr, pOverlapped:Int )
Function ReadFile:Int( handle:Int, pBuffer:Byte Ptr, NumberOfBytesToRead:Int, pNumberOfBytesRead:Byte Ptr, pOverlapped:Int )

Function GetLastError:Int()
Function FormatMessage:Int( dwFlags:Int=$100,lpSource:Byte Ptr, dwMessageId:Int, dwLanguageId:Int, lpBuffer:Byte Ptr, nSize:Int )

End Extern

Const GENERIC_READ = $80000000
Const GENERIC_WRITE = $40000000
Const OPEN_EXISTING = 3
Const FILE_ATTRIBUTE_NORMAL = $80
Const INVALID_HANDLE_VALUE = -1


Global temp:String = "COM1"
Global buffer:TBank = CreateBank(1024)
Global count:TBank = CreateBank(4)

Global handle = CreateFileA( temp.ToCString(), GENERIC_READ Or GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0 )

PokeByte(buffer,0,1)

Print "WRITE " + WriteFile( handle, BankBuf(buffer), 1, BankBuf(count), 0 )
Print GetLastError() 'ACCESS DENIED ERROR HERE

CloseHandle(handle)
WaitKey()
End


skidracer(Posted 2005) [#2]
Or is no longer a binary operator in BlitzMax (it's now logical), try the | operator instead (generic_read|generic_write).


Nigel Brown(Posted 2005) [#3]
thanks, spot on. now I can release the comm module for blitz max :-)