Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Reading open files

Posted on 1997-03-25
4
Medium Priority
?
198 Views
Last Modified: 2010-05-18
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...
0
Comment
Question by:tier
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
mheacock earned 200 total points
ID: 1334954
This may or may not work...but you might try copying it to
a temporary directory, reading from it, then deleting it.

My guess is that it won't work (in which case reject my answer),
but it is worth a try.
0
 
LVL 1

Author Comment

by:tier
ID: 1334955
No, this does not work...
0
 
LVL 3

Expert Comment

by:mheacock
ID: 1334956
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.
0
 
LVL 1

Expert Comment

by:slp
ID: 1334957
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

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question