My solution in [WayBack] delphi – post-build event with multiple if/copy combinations only execute if first file does not exist – Stack Overflow is an addendum to my 2014 post Delphi prebuild/prelink/postbuild events.
Here we go:
Posted by jpluimers on 2018/11/15
My solution in [WayBack] delphi – post-build event with multiple if/copy combinations only execute if first file does not exist – Stack Overflow is an addendum to my 2014 post Delphi prebuild/prelink/postbuild events.
Here we go:
Posted in Conference Topics, Conferences, Delphi, Development, Event, Software Development, The Old New Thing, Windows Development | Leave a Comment »
Posted by jpluimers on 2018/10/31
Answering [WayBack] delphi – post-build event with multiple if/copy combinations only execute if first file does not exist – Stack Overflow made me do a quick search for parentheses handling in batch files. TL;DR: it is a mess.
But it reveals some interesting links:
–jeroen
Posted in Batch-Files, Conference Topics, Conferences, Development, Event, Scripting, Software Development, Windows Development | Leave a Comment »
Posted by jpluimers on 2018/10/24
Via: [WayBack] I just returned from lunch break and found my program faulted with an “Access Denied” (Error code 5) error in a call to Mouse.GetCoursorPos and was wond… – Thomas Mueller (dummzeuch) – Google+:
All of [WayBack] GetCursorPos, [WayBack] GetCursorInfo and [WayBack] GetKeyState can cause an “Access Denied” (Error code 5) when they do not have permission for the current desktop (for instance the logon desktop when a screen-saver has kicked in).
Solution: write a wrapper around it then [WayBack] patch calls going to the original into the patch [WayBack] delphi – Explain errors from GetKeyState / GetCursorPos – Stack Overflow
–jeroen
Posted in .NET, C#, C++, Delphi, Development, Software Development, Windows Development | Leave a Comment »
Posted by jpluimers on 2018/10/17
This has a really neat Windows API trick [WayBack] delphi – How can I sanitize a string for use as a filename? – Stack Overflow by [WayBack] Alex.
Via: [WayBack] Interesting use of MoveFile, with NIL as the first parameter. https://stackoverflow.com/a/961500/49925 – Thomas Mueller (dummzeuch) – Google+
function IsValidFilePath(const FileName: String): Boolean; var S: String; I: Integer; begin Result := False; S := FileName; repeat I := LastDelimiter('\/', S); MoveFile(nil, PChar(S)); if (GetLastError = ERROR_ALREADY_EXISTS) or ( (GetFileAttributes(PChar(Copy(S, I + 1, MaxInt))) = INVALID_FILE_ATTRIBUTES) and (GetLastError=ERROR_INVALID_NAME) ) then Exit; if I>0 then S := Copy(S,1,I-1); until I = 0; Result := True; end;
–jeroen
Posted in Delphi, Development, Software Development, Windows Development | 3 Comments »
Posted by jpluimers on 2018/09/12
States via [WayBack] SERVICE_STATUS structure (Windows)
Value Hex Meaning SERVICE_CONTINUE_PENDING 0x00000005 The service continue is pending. SERVICE_PAUSE_PENDING 0x00000006 The service pause is pending. SERVICE_PAUSED 0x00000007 The service is paused. SERVICE_RUNNING 0x00000004 The service is running. SERVICE_START_PENDING 0x00000002 The service is starting. SERVICE_STOP_PENDING 0x00000003 The service is stopping. SERVICE_STOPPED 0x00000001 The service is not running.
It’s complex as a table, so there are two.
Common transitions:
| From state | To state |
|---|---|
| SERVICE_STOPPED | SERVICE_START_PENDING |
| SERVICE_START_PENDING | SERVICE_RUNNING |
| SERVICE_START_PENDING | SERVICE_STOPPED |
| SERVICE_START_PENDING | SERVICE_STOP_PENDING |
| SERVICE_RUNNING | SERVICE_STOPPED |
| SERVICE_RUNNING | SERVICE_STOP_PENDING |
| SERVICE_STOP_PENDING | SERVICE_STOPPED |
Infrequent transitions:
| From state | To state |
|---|---|
| SERVICE_RUNNING | SERVICE_PAUSE_PENDING |
| SERVICE_RUNNING | SERVICE_PAUSED |
| SERVICE_PAUSE_PENDING | SERVICE_PAUSED |
| SERVICE_PAUSE_PENDING | SERVICE_STOP_PENDING |
| SERVICE_PAUSE_PENDING | SERVICE_STOPPED |
| SERVICE_PAUSED | SERVICE_RUNNING |
| SERVICE_PAUSED | SERVICE_CONTINUE_PENDING |
| SERVICE_PAUSED | SERVICE_STOP_PENDING |
| SERVICE_PAUSED | SERVICE_STOPPED |
| SERVICE_CONTINUE_PENDING | SERVICE_RUNNING |
| SERVICE_CONTINUE_PENDING | SERVICE_STOP_PENDING |
| SERVICE_CONTINUE_PENDING | SERVICE_STOPPED |
Posted in Development, Software Development, Windows Development | Leave a Comment »
Posted by jpluimers on 2018/09/11
On x86/x64/ARM/…:
It’s where the function is going to return to, not where it came from.
And:
Bonus chatter: This reminds me of a quirk of the 6502 processor: When it pushed the return address onto the stack, it actually pushed the return address minus one. This is an artifact of the way the 6502 is implemented, but it results in the nice feature that the stack trace gives you the line number of the call instruction.
Of course, this is all hypothetical, because 6502 debuggers didn’t have fancy features like stack traces or line numbers.
Source: [WayBack] Remember that in a stack trace, the addresses are return addresses, not call addresses – The Old New Thing
Which resulted in these comments at [WayBack] CC +mos6502 – Jeroen Wiert Pluimers – Google+:
- mos6502: And don’t forget the crucial difference in PC on 6502 between RTS and RTI!
- Jeroen Wiert Pluimers: +mos6502 I totally forgot about that one. Thanks for reminding me
<<Note that unlike RTS, the return address on the stack is the actual address rather than the address-1.>>
References:
[WayBack] 6502.org: Tutorials and Aids – RTI
RTI retrieves the Processor Status Word (flags) and the Program Counter from the stack in that order (interrupts push the PC first and then the PSW).
Note that unlike RTS, the return address on the stack is the actual address rather than the address-1.
[WayBack] 6502.org: Tutorials and Aids – RTS
RTS pulls the top two bytes off the stack (low byte first) and transfers program control to that address+1. It is used, as expected, to exit a subroutine invoked via JSR which pushed the address-1.
RTS is frequently used to implement a jump table where addresses-1 are pushed onto the stack and accessed via RTS eg. to access the second of four routines.
–jeroen
Posted in 6502, 6502 Assembly, Assembly Language, Development, History, Software Development, The Old New Thing, Windows Development, x64, x86 | Leave a Comment »
Posted by jpluimers on 2018/08/16
Cool feature borrowed from Notepad, which can read files locked by other references (for instance a process having the handle open): [WayBack] c# – Notepad beats them all? – Stack Overflow.
The example from the answer is in .NET, but can be used in a native environment as well (Notepad is a native application).
Notepad reads files by first mapping them into memory, rather than using the “usual” file reading mechanisms presumably used by the other editors you tried. This method allows reading of files even if they have an exclusive range-based locks.
You can achieve the same in C# with something along the lines of:
using (var f = new FileStream(processIdPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) using (var m = MemoryMappedFile.CreateFromFile(f, null, 0, MemoryMappedFileAccess.Read, null, HandleInheritability.None, true)) using (var s = m.CreateViewStream(0, 0, MemoryMappedFileAccess.Read)) using (var r = new StreamReader(s)) { var l = r.ReadToEnd(); Console.WriteLine(l); }
Via: [WayBack] Maintaining Notepad is not a full-time job, but it’s not an empty job either – The Old New Thing
–jeroen
Posted in .NET, Delphi, Development, Software Development, The Old New Thing, Windows Development | Leave a Comment »
Posted by jpluimers on 2018/05/09
For my research list:
–jeroen
Posted in Development, Software Development, The Old New Thing, Windows Development | Leave a Comment »
Posted by jpluimers on 2018/05/08
create the directory without an explicit security descriptor and let the experts create it with the default security descriptor, which takes into account all the inheritance rules. And then modify the security descriptor post-creation to include the new ACE you want. Fortunately, MSDN has sample code for how to add an ACE to an existing security descriptor.
via: [WayBack] How to create a folder that inherits its parent’s ACL, and then overrides part of it – The Old New Thing
–jeroen
Posted in Development, Software Development, The Old New Thing, Windows Development | Leave a Comment »
Posted by jpluimers on 2018/04/17
I needed a TTemporaryFileStream and found it at [WayBack] DELPHI AREA » How to have a temporary stream, with no size limit.
It taught me that CreateFileA and CreateFileW (the ANSI and Unicode versions of [WayBack] CreateFile function (Windows)) accept a FILE_FLAG_DELETE_ON_CLOSE parameter, so as soon as you close the handle, Windows will dispose of the file.
Note however that this will apply to the file handle so if you want to open it multiple times, you need [WayBack] DuplicateHandle function (Windows) as per [Archive.is] The FILE_FLAG_DELETE_ON_CLOSE flag applies to the handle, also known as the file object, which is not the same as the file – The Old New Thing
–jeroen
Posted in Delphi, Development, Software Development, The Old New Thing, Windows Development | Leave a Comment »