Page 1 of 2
Problem with CreateFile_()
Posted: Sun Feb 28, 2016 8:34 pm
by zgneng
Code: Select all
q.l= CreateFile_("c:\888.txt", #GENERIC_READ, 0, 0, #OPEN_ALWAYS, #FILE_ATTRIBUTE_NORMAL, 0)
Global a.s{10000000}
Debug q
ReadFile_(q, @a, 9, #Null, #Null)
Do not use the PUREBASIC function(CreateFile AND ReadFile)
Using windows APi(CreateFile_,ReadFile)_
You will find BUG
OK
Code: Select all
Procedure.s GETFILETXT(PATH.l);文件名地址
sbuff.l;返回长度
Filehwnd.l= CreateFile_(PATH, #GENERIC_READ, 0, 0, #OPEN_ALWAYS, #FILE_ATTRIBUTE_NORMAL, 0)
If Filehwnd
fsize.l=GetFileSize_(Filehwnd,#Null) ;文件长度
STRR.S=Space(fsize);填充长度
ReadFile_(Filehwnd,@STRR,fsize,@sbuff,0)
CloseHandle_(Filehwnd)
EndIf
ProcedureReturn STRR
EndProcedure
__________________________________________________
Title changed
29.02.2016
RSBasic
Re: purebasic BUG
Posted: Sun Feb 28, 2016 9:13 pm
by Fred
which bug ?
Re: purebasic BUG
Posted: Sun Feb 28, 2016 9:16 pm
by falsam
Fred wrote:which bug ?
Root disk acces ?
Try this code
Code: Select all
q.l= CreateFile_(GetHomeDirectory()+"Desktop/888.txt", #GENERIC_READ, 0, 0, #OPEN_ALWAYS, #FILE_ATTRIBUTE_NORMAL, 0)
Global a.s{10000000}
Debug q
ReadFile_(q, @a, 9, #Null, #Null)
Question : Why not use the native features of PureBasic?
Re: purebasic BUG
Posted: Sun Feb 28, 2016 9:54 pm
by bbanelli
I'm getting IMA (write error at address 0) for both OP's and falsam's example.
Re: purebasic BUG
Posted: Sun Feb 28, 2016 10:01 pm
by falsam
bbanelli wrote:I'm getting IMA (write error at address 0) for both OP's and falsam's example.
[Window 10] [PB 5.42 x86] No IMA. The file is created.
Re: purebasic BUG
Posted: Sun Feb 28, 2016 10:12 pm
by fryquez
No,bug See MSDN
lpNumberOfBytesRead [out, optional]
A pointer to the variable that receives the number of bytes read when using a synchronous hFile parameter. ReadFile sets this value to zero before doing any work or error checking. Use NULL for this parameter if this is an asynchronous operation to avoid potentially erroneous results.
This parameter can be NULL only when the lpOverlapped parameter is not NULL.
For more information, see the Remarks section.
Re: purebasic BUG
Posted: Mon Feb 29, 2016 4:05 am
by zgneng
fryquez wrote:No,bug See MSDN
lpNumberOfBytesRead [out, optional]
A pointer to the variable that receives the number of bytes read when using a synchronous hFile parameter. ReadFile sets this value to zero before doing any work or error checking. Use NULL for this parameter if this is an asynchronous operation to avoid potentially erroneous results.
This parameter can be NULL only when the lpOverlapped parameter is not NULL.
For more information, see the Remarks section.
No solution yet
powerbasic no problem
Re: purebasic BUG
Posted: Mon Feb 29, 2016 4:07 am
by zgneng
falsam wrote:Fred wrote:which bug ?
Root disk acces ?
Try this code
Code: Select all
q.l= CreateFile_(GetHomeDirectory()+"Desktop/888.txt", #GENERIC_READ, 0, 0, #OPEN_ALWAYS, #FILE_ATTRIBUTE_NORMAL, 0)
Global a.s{10000000}
Debug q
ReadFile_(q, @a, 9, #Null, #Null)
Question : Why not use the native features of PureBasic?
Want to know the problem
No solution yet
powerbasic no problem
Re: purebasic BUG
Posted: Mon Feb 29, 2016 4:26 am
by TI-994A
falsam wrote:[Window 10] [PB 5.42 x86] No IMA. The file is created.
Yes; no IMA
(Windows 8.1 with PureBasic v5.41 LTS x64).
Re: purebasic BUG
Posted: Mon Feb 29, 2016 4:35 am
by zgneng
TI-994A wrote:falsam wrote:[Window 10] [PB 5.42 x86] No IMA. The file is created.
Yes; no IMA
(Windows 8.1 with PureBasic v5.41 LTS x64).
Want to know the problem
No solution yet
powerbasic no problem
Re: purebasic BUG
Posted: Mon Feb 29, 2016 4:51 am
by Thunder93
You are going about this the wrong way.
You say there is a problem with PB and Win API usage, but you don't provide anything other than a bug cry. You expect a solution, you repeatedly posts that powerbasic has no problem. You aren't discovering a bug, you are discovering that you are lacking understanding of what's happening.
You trying to create a file 888.txt on the root drive. CreateFile_() is failing because of permissions restrictions. Of course ReadFile_() will fail next.
Re: purebasic BUG
Posted: Mon Feb 29, 2016 7:48 am
by infratec
Solution:
Use PB commands, no problem.
Or use PowerBasic.
Also no problem with this.
Re: purebasic BUG
Posted: Mon Feb 29, 2016 8:00 am
by mhs
infratec wrote:Solution:
Use PB commands, no problem.
Or use PowerBasic.
Also no problem with this.
+1
PS: falsams code schould be working...
Re: purebasic BUG
Posted: Mon Feb 29, 2016 8:45 am
by zgneng
mhs wrote:infratec wrote:Solution:
Use PB commands, no problem.
Or use PowerBasic.
Also no problem with this.
+1
PS: falsams code schould be working...
Code: Select all
Procedure.s GETFILETXT(PATH.l);文件名地址
sbuff.l;返回长度
Filehwnd.l= CreateFile_(PATH, #GENERIC_READ, 0, 0, #OPEN_ALWAYS, #FILE_ATTRIBUTE_NORMAL, 0)
If Filehwnd
fsize.l=GetFileSize_(Filehwnd,#Null) ;文件长度
STRR.S=Space(fsize);填充长度
ReadFile_(Filehwnd,@STRR,fsize,@sbuff,0)
CloseHandle_(Filehwnd)
EndIf
ProcedureReturn STRR
EndProcedure
Re: purebasic resolved
Posted: Mon Feb 29, 2016 3:34 pm
by Thunder93
This is the first step into the right direction, my friend. However it usually helps to offer little description of the problem you experiencing, regardless how obvious it may be to you.
Code: Select all
Procedure.s GETFILETXT(*PATH)
sbuff.l
hFile.l= CreateFile_(*PATH, #GENERIC_READ, 0, 0, #OPEN_EXISTING, #FILE_ATTRIBUTE_NORMAL, 0)
If hFile <> #INVALID_HANDLE_VALUE
fsize.l=GetFileSize_(hFile,#Null)
STRR.S=Space(fsize)
ReadFile_(hFile,@STRR,fsize,@sbuff,0)
CloseHandle_(hFile)
If #PB_Compiler_Unicode : STRR = PeekS(@STRR, MemoryStringLength(@STRR), #PB_Ascii) : EndIf
Else
STRR = "Oops! What Happened?!?! ;p"
EndIf
ProcedureReturn STRR
EndProcedure
Debug GETFILETXT(@"C:\OutOfTheBox\888.txt")
Giving that no description of the problem was provided. I'll just post an example that works for me in ASCII and Unicode modes.