Solved

Reading open files

Posted on 1997-03-25
4
167 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
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
mheacock earned 100 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

759 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now