-
Oct 8th, 2024, 07:17 PM
#1
Thread Starter
New Member
VB6 and win 10, total power shutdown and restart problem.
So here is the thing.
It is a CNC machine tool.
Every cycle it writes a status file of what is going on.
So one pulls the big red switch and then flip it on. At boot up it knows what was what.
All fine under win 95,98,7 etc. It has been only windows 10 that has left me with a zero byte empty file.
Now on reboot I get a blank zero length file so my application is not a happy camper and dies or says oh-chit.
I did the turn off disk cache thing under this drive.. no help here to my surprise.
So I am in VB6 using open and close. How do I force an actual flush at file output time?
This file has to be written now and not stored.
Do I need to use the file system API for open and close?
Even so will I be guaranteed the file has been written?
If after writing and then I open the same file as "append" and then close it will this force a update to the disk?
Yes I know killing the power to win 10 is a problem but how to get around it.
Pushing the shutdown win 10 thing works but that is not an option.
Power off to the CPU is many, many seconds out. I need to be sure the file was actually written to the drive.
I also get that some newer drives will report back to the OS the write made before they have actually done it but I would think this small in time.
Fun stuff.
Bob
-
Oct 8th, 2024, 11:38 PM
#2
Re: VB6 and win 10, total power shutdown and restart problem.
You should use API methods that let you control this; like open/create the file with CreateFile using the FILE_FLAG_WRITE_THROUGH and FILE_FLAG_NO_BUFFERING flag, which makes write operations skip any buffer and go directly to disk. Make sure you read and follow the additional requirements of the latter flag.
-
Oct 9th, 2024, 05:20 AM
#3
Re: VB6 and win 10, total power shutdown and restart problem.
> I did the turn off disk cache thing under this drive.. no help here to my surprise.
This is very much needed in your case *and* switching off drive cache on the disk controller unless it's battery backed one.
> Do I need to use the file system API for open and close?
Yes, if you want to try FILE_FLAG_WRITE_THROUGH or the alternative option w/ FlushFileBuffers API call -- it accepts file handle.
cheers,
</wqw>
-
Oct 9th, 2024, 05:18 PM
#4
Thread Starter
New Member
Re: VB6 and win 10, total power shutdown and restart problem.
I am a new rookie here to this forum.
Thanks for the quick response.
I have never used the API CreateFile call under VB6.
It has been over 40 year since I did direct disk I/O and that was Z80 code written in hex.
So please help an old man out.
Anyone have some raw boilerplate code on this? Just the basics. I need the headers, call and such.
Yes I can dig this out but others have done it.... so the ask.
I found it a few days back but I closed the tab and can't find it again. (call me ..dumb Bob).
It hurts me so bad to have to ask such a question
Also I wonder if it was stored on a removal drive (usb) would windows 10 still do the "lazy" write. I would think it would write faster since a user might pull that drive. Yes/no??
This program is only around 85,000 lines of VB6 code.
So far I only have had to maintain one version from win 95 to now.
It is a simple if statement I know in the code and so be it.
I thank the above for helping answer my question and big yes.
Now I just have to make it work.
Just to make it more fun I have 14 hours to patch a fix here or I will look like an idiot.
Bob
Last edited by cbbobd; Oct 9th, 2024 at 05:38 PM.
-
Oct 9th, 2024, 11:16 PM
#5
Re: VB6 and win 10, total power shutdown and restart problem.
Code:
Public Enum StandardAccessTypes
DELETE = (&H00010000)
READ_CONTROL = (&H00020000)
WRITE_DAC = (&H00040000)
WRITE_OWNER = (&H00080000)
SYNCHRONIZE = (&H00100000)
STANDARD_RIGHTS_REQUIRED = (&H000F0000)
STANDARD_RIGHTS_READ = (READ_CONTROL)
STANDARD_RIGHTS_WRITE = (READ_CONTROL)
STANDARD_RIGHTS_EXECUTE = (READ_CONTROL)
STANDARD_RIGHTS_ALL = (&H001F0000)
SPECIFIC_RIGHTS_ALL = (&H0000FFFF&)
' //
' // AccessSystemAcl access type
' //
ACCESS_SYSTEM_SECURITY = (&H01000000)
MAXIMUM_ALLOWED = (&H02000000)
End Enum
Public Enum GenericRights
GENERIC_READ = (&H80000000)
GENERIC_WRITE = (&H40000000)
GENERIC_EXECUTE = (&H20000000)
GENERIC_ALL = (&H10000000)
End Enum
Public Enum FileAccessRights
FILE_READ_DATA = (&H0001) ' file & pipe
FILE_LIST_DIRECTORY = (&H0001) ' directory
FILE_WRITE_DATA = (&H0002) ' file & pipe
FILE_ADD_FILE = (&H0002) ' directory
FILE_APPEND_DATA = (&H0004) ' file
FILE_ADD_SUBDIRECTORY = (&H0004) ' directory
FILE_CREATE_PIPE_INSTANCE = (&H0004) ' named pipe
FILE_READ_EA = (&H0008) ' file & directory
FILE_WRITE_EA = (&H0010) ' file & directory
FILE_EXECUTE = (&H0020) ' file
FILE_TRAVERSE = (&H0020) ' directory
FILE_DELETE_CHILD = (&H0040) ' directory
FILE_READ_ATTRIBUTES = (&H0080) ' all
FILE_WRITE_ATTRIBUTES = (&H0100) ' all
FILE_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &H1FF)
FILE_GENERIC_READ = (STANDARD_RIGHTS_READ Or FILE_READ_DATA Or FILE_READ_ATTRIBUTES Or FILE_READ_EA Or SYNCHRONIZE)
FILE_GENERIC_WRITE = (STANDARD_RIGHTS_WRITE Or FILE_WRITE_DATA Or FILE_WRITE_ATTRIBUTES Or FILE_WRITE_EA Or FILE_APPEND_DATA Or SYNCHRONIZE)
FILE_GENERIC_EXECUTE = (STANDARD_RIGHTS_EXECUTE Or FILE_READ_ATTRIBUTES Or FILE_EXECUTE Or SYNCHRONIZE)
End Enum
Public Enum FileShareMode
FILE_SHARE_READ = &H00000001
FILE_SHARE_WRITE = &H00000002
FILE_SHARE_DELETE = &H00000004
End Enum
Public Enum CreateFileDisposition
CREATE_NEW = 1
CREATE_ALWAYS = 2
OPEN_EXISTING = 3
OPEN_ALWAYS = 4
TRUNCATE_EXISTING = 5
End Enum
Public Enum FILE_FLAGS
FILE_FLAG_IGNORE_IMPERSONATED_DEVICEMAP = &H00020000
FILE_FLAG_OPEN_REQUIRING_OPLOCK = &H00040000
FILE_FLAG_FIRST_PIPE_INSTANCE = &H00080000
FILE_FLAG_OPEN_NO_RECALL = &H00100000
FILE_FLAG_OPEN_REPARSE_POINT = &H00200000
FILE_FLAG_SESSION_AWARE = &H00800000
FILE_FLAG_POSIX_SEMANTICS = &H01000000
FILE_FLAG_BACKUP_SEMANTICS = &H02000000
FILE_FLAG_DELETE_ON_CLOSE = &H04000000
FILE_FLAG_SEQUENTIAL_SCAN = &H08000000
FILE_FLAG_RANDOM_ACCESS = &H10000000
FILE_FLAG_NO_BUFFERING = &H20000000
FILE_FLAG_OVERLAPPED = &H40000000
FILE_FLAG_WRITE_THROUGH = &H80000000
End Enum
Public Enum FILE_ATTRIBUTES
INVALID_FILE_ATTRIBUTES = -1
FILE_ATTRIBUTE_READONLY = &H00000001
FILE_ATTRIBUTE_HIDDEN = &H00000002
FILE_ATTRIBUTE_SYSTEM = &H00000004
FILE_ATTRIBUTE_DIRECTORY = &H00000010 'Read only
FILE_ATTRIBUTE_ARCHIVE = &H00000020
FILE_ATTRIBUTE_DEVICE = &H00000040
FILE_ATTRIBUTE_NORMAL = &H00000080
FILE_ATTRIBUTE_TEMPORARY = &H00000100
FILE_ATTRIBUTE_SPARSE_FILE = &H00000200 'Read only
FILE_ATTRIBUTE_REPARSE_POINT = &H00000400 'Read only
FILE_ATTRIBUTE_COMPRESSED = &H00000800
FILE_ATTRIBUTE_OFFLINE = &H00001000
FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = &H00002000
FILE_ATTRIBUTE_ENCRYPTED = &H00004000
FILE_ATTRIBUTE_INTEGRITY_STREAM = &H00008000&
FILE_ATTRIBUTE_VIRTUAL = &H00010000
FILE_ATTRIBUTE_NO_SCRUB_DATA = &H00020000
FILE_ATTRIBUTE_EA = &H00040000
FILE_ATTRIBUTE_RECALL_ON_OPEN = &H00040000
FILE_ATTRIBUTE_PINNED = &H000080000
FILE_ATTRIBUTE_UNPINNED = &H00100000
FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS = &H400000
FILE_ATTRIBUTE_STRICTLY_SEQUENTIAL = &H20000000
End Enum
Public Declare Function CreateFileW Lib "kernel32" (ByVal lpFileName As LongPtr, ByVal dwDesiredAccess As Long, ByVal dwShareMode As FileShareMode, lpSecurityAttributes As Any, ByVal dwCreationDisposition As CreateFileDisposition, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As LongPtr) As LongPtr
Public Declare Function WriteFile Lib "kernel32" (ByVal hFile As LongPtr, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, ByVal lpOverlapped As LongPtr) As Long
Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As LongPtr) As Long
As always if you're not using oleexp or otherwise haven't defined it,
Code:
#If VBA7 = 0 Then
Public Enum LongPtr
[_]
End Enum
#End If
-
Oct 11th, 2024, 09:25 AM
#6
Hyperactive Member
Re: VB6 and win 10, total power shutdown and restart problem.
Did this work for you, op?
In the long term I'd suggest using a smart UPS to trigger a proper shutdown or use Windows Iot with Unified Write Filter:
https://learn.microsoft.com/en-us/wi...d-write-filter
-
Oct 15th, 2024, 09:38 AM
#7
Thread Starter
New Member
Re: VB6 and win 10, total power shutdown and restart problem.
A big thanks for the help here.
Right now I have gone to a temporary fix of using a USB drive to store the file on.
We have cycled power over 100 times and not had a failure
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|