Copied directly from exaple book but not working....
All i get is an empty 0 byte file
Call to GetLastError directly after the call to WriteFile returns 0
(NO_ERROR) but no data sees to be written :-(
??????????
Thx
The code:
Declare Function CreateFile Lib "kernel32.dll" Alias "CreateFileA" (ByVal
lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As
Long, lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long,
ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As
Long
Declare Function WriteFile Lib "kernel32.dll" (ByVal hFile As Long, lpBuffer
As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long,
lpOverlapped As Any) As Long
Declare Function ReadFile Lib "kernel32.dll" (ByVal hFile As Long, lpBuffer
As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long,
lpOverlapped As Any) As Long
Declare Function GetLastError Lib "kernel32.dll" () As Long
Const GENERIC_READ = &H80000000
Const GENERIC_WRITE = &H40000000
Const FILE_SHARE_READ = &H1
Const FILE_SHARE_WRITE = &H2
Const CREATE_ALWAYS = 2
Const CREATE_NEW = 1
Const OPEN_ALWAYS = 4 'Create if doesn't exist
Const OPEN_EXISTING = 3
Const TRUNCATE_EXISTING = 5
Const FILE_ATTRIBUTE_ARCHIVE = &H20
Public Sub test()
Dim longbuffer As Long ' long to write to the file
Dim stringbuffer As String ' string to write to the file
Dim numwritten As Long ' receives number of bytes written to the file
Dim hFile As Long ' handle of the open file
Dim retval As Long ' return value
' Open or create the file being written to.
hFile = CreateFile(App.Path & "\test.txt", GENERIC_WRITE, FILE_SHARE_READ,
ByVal CLng(0), OPEN_ALWAYS, FILE_ATTRIBUTE_ARCHIVE, 0)
If hFile = -1 Then ' the file could not be opened
Debug.Print "Unable to open the file -- it probably does not exist."
End ' abort the program
End If
stringbuffer = "Anonymous!"
retval = WriteFile(hFile, ByVal stringbuffer, 10, numwritten, CLng(0))
MsgBox GetLastError
retval = CloseHandle(hFile)
End Sub 4 8559
Isn't this ~below! easier?
open "c:\text.text" for output as #1
print #1, "Anonymous!"
close #1
You can do checks and things to see if the file exists and if it has data.
you can link it to the commondialog control as well.
--
Regards
Dillon Mantle
"dim" <di****@hotpop.com> wrote in message news:<dR********************@newsc.telia.net>...
<cut> hFile = CreateFile(App.Path & "\test.txt", GENERIC_WRITE, FILE_SHARE_READ, ByVal CLng(0), OPEN_ALWAYS, FILE_ATTRIBUTE_ARCHIVE, 0)
Note that App.Path can sometimes end with a trailing \ and that will
cause the above line to fail. It's not causing your immediate problem
but is something you should be aware of. I usually do something like:
dim sPath as string
sPath=app.path
if right$(spath,1)<>"\" then spath=spath & "\"
hFile = CreateFile(sPath & "test.txt", ...
<cut> End ' abort the program
You should not use END since it does not allow normal cleanup
operations to complete. A VB app NEVER needs the END statement and
using it can cause data corruption and memory leaks. VB apps end when
no forms are loaded and no code is running.
<cut> retval = WriteFile(hFile, ByVal stringbuffer, 10, numwritten, CLng(0))
That line is your problem. Your code works if you change it to read:
retval = WriteFile(hFile, ByVal stringbuffer, 10, numwritten, ByVal
CLng(0))
you were passing a pointer to a zero which the API tried to interpret
as the overlapped operation parameter.
MsgBox GetLastError
The GetLastError API call is useless from VB because VB itself trashes
the value there. Fortunately it saves it for you before trashing it:
MsgBox Err.LastDLLError
"Bob Butler" <bu*******@earthlink.net> wrote in message
news:fa*************************@posting.google.co m... "dim" <di****@hotpop.com> wrote in message
news:<dR********************@newsc.telia.net>... <cut> <cut> retval = WriteFile(hFile, ByVal stringbuffer, 10, numwritten,
CLng(0)) That line is your problem. Your code works if you change it to read: retval = WriteFile(hFile, ByVal stringbuffer, 10, numwritten, ByVal CLng(0))
Is Bob a detective or what?
you were passing a pointer to a zero which the API tried to interpret as the overlapped operation parameter.
I'm gonna save that line for the next tech support call I get...I can
pretend I know what it means as well as the next guy...<g>
"Steve Gerrard" <no*************@comcast.net> wrote in message news:<9P********************@comcast.com>... "Bob Butler" <bu*******@earthlink.net> wrote in message news:fa*************************@posting.google.co m...
<cut> you were passing a pointer to a zero which the API tried to interpret as the overlapped operation parameter.
I'm gonna save that line for the next tech support call I get...I can pretend I know what it means as well as the next guy...<g>
LOL; it does sound pretty cryptic at that, doesn't it? I should have
just given the standard response: User Error This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: |
last post by:
Hello, I hope someone will help me or I will have to dive from 11th floor.
Why this --> test = @"Melanie "Jets" Riggs" doesnt work in asp? I need
something like that and I dont know how to make it...
|
by: Station Media |
last post by:
Hi,
here my problem, i use stored procedure in ACCESS database(latest
version), and i would like to use this procedure but it doesnt work,
do you know why ?
Procedure:
PARAMETERS MyField Text...
|
by: Clouds |
last post by:
Hi !
How do I add the dynamic event handler for a dropdownlist present in the
itemtemplate of a datalist !!
I am doing it in the itemdatabound event of the datalist but it doesnt
work... I am...
|
by: Juna |
last post by:
I have been working in vs2003, but now started to work in
vs2005 but the problem,
I have simple web application not website, which work i mean open in
browser when we press F5 or run the...
|
by: Digital Don |
last post by:
I am writing a program for Peg solitaire...
To check for no repetition of previous states I use a Set for storage of Board states..
The pronblem is when I declare the set as type char i.e. set...
|
by: jx2 |
last post by:
hi guys
i would appriciate your coments on this code - when i ran it for the very first time it doesnt see @last = LAST_INSERT_ID() but when i ran it next time it read it properly i need to know it...
|
by: Dany13 |
last post by:
hi all.
i using some text box for input value and some localvarible for passing this data to dataset . give instance for correct row of dataset and data in data table . use one gird view for...
|
by: Hush |
last post by:
Hi,
The following code works fine in IE7 but FF returns with an error:
Access denied to achieve the property Element.firstChild. In this
line:
nodes = xmlDoc.documentElement.childNodes;
My...
|
by: AGP |
last post by:
I've been scratching my head for weeks to understand why some code doesnt
work for me.
here is what i have:
dim sVal as string = "13.2401516"
dim x as double
x = sVal
debug.writeline ( x)
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
|
by: Matthew3360 |
last post by:
Hi,
I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
|
by: Ricardo de Mila |
last post by:
Dear people, good afternoon...
I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control.
Than I need to discover what...
| |