tier
asked on
Reading open files
I wrote a program in Delphi2 that needs to read data that has been appended to the executable of this program. It is not able to read data from the executable when it's running. I guess this is because the file is open and denies any access to itself. Is there any workaround for this?
As far as I remember this has been possible with Pascal in DOS...
As far as I remember this has been possible with Pascal in DOS...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This should work:
Use the Win32 API function CreateFile as follows:
//open main file
handle := CreateFile(pchar(exepath), generic_read,
file_share_read, nil, open_existing,
FILE_ATTRIBUTE_NORMAL, 0);
where "exepath" is an ansistring containing the path to the executable you wish you open.
Use the Win32 API function CreateFile as follows:
//open main file
handle := CreateFile(pchar(exepath),
file_share_read, nil, open_existing,
FILE_ATTRIBUTE_NORMAL, 0);
where "exepath" is an ansistring containing the path to the executable you wish you open.
I'm curious as to how you appended the data to the executable. One "Windows approved" way of doing something like this that is supported by the API is to add your data as a resource, then you don't have to worry about finding the file, file locking, sharing violations or anything else of the sort.
SLP
SLP
ASKER