From: R.Wieser on
Hello all,

Some time ago I made a small app which generated data (in memory) which I
wanted to view using available programs on my computer (notepad/wordpad for
text, IE for most images, media-player for most sounds, etc).

The problem is that I do not want the data to persist after the program
which displays it to me closes.

I used a temporary file and some trickery to (barily) get it to work, but
recently the idea broke down : a .PNG image caused IExplorer.exe to display
a "what do you want to do with this file" dialog (probably caused by the
OS-generated temporary filename allways having an .TMP extension), and the
changes that I made (creating a normal file using the correct extension)
also killed the automatic removal-after-usage of the file.

And that brings me to my actual question : Is there a way to start an
application with some data that is only there for that app, and disappears
(preferrably handled by the OS) when the app does not need it anymore.

Regards,
Rudy Wieser



From: Leo Davidson on
On Aug 8, 7:09 pm, "R.Wieser" <addr...(a)not.available> wrote:

> (probably caused by the
> OS-generated temporary filename allways having an .TMP extension), and the
> changes that I made (creating a normal file using the correct extension)
> also killed the automatic removal-after-usage of the file.

Windows does not impose any extension requirements on temp files. How
were you creating the file? What did you change it to which broke
things?
From: R.Wieser on
Hello Leo,

> Windows does not impose any extension requirements on temp files.

Yes, it does. Not on "temporary files" in general, but certainly on a
"temporary file*name*" generated by the GetTempFileName function in
Kernel32.

> How were you creating the file?

By using CreateFile with the arguments {filename},
GENERIC_WRITE,0,0,CREATE_ALLWAYS,FILE_ATTRIBUTE_READONLY,0

> What did you change it to which broke things?

By replacing the above GetTempFileName function with a PathAppend using the
origional filename (containing the correct extension).

I also tried adding the FILE_FLAG_DELETE_ON_CLOSE flag when creating the
file, but that did not change anything .

As you see, a minimal change at best.

Remark : The "trick" I used was to close the temporary file about a second
after I started the app (using ShellExecute). This is also why I used the
FILE_ATTRIBUTE_READONLY flag, otherwise the app would lock the file and not
allow it to be closed.

Regards,
Rudy Wieser


-- Origional message:
Leo Davidson <leonudeldavidson(a)gmail.com> schreef in berichtnieuws
4b3e02ae-a190-4218-a4df-53dcc9b433e3(a)e15g2000yqo.googlegroups.com...
On Aug 8, 7:09 pm, "R.Wieser" <addr...(a)not.available> wrote:

> (probably caused by the
> OS-generated temporary filename allways having an .TMP extension), and the
> changes that I made (creating a normal file using the correct extension)
> also killed the automatic removal-after-usage of the file.

Windows does not impose any extension requirements on temp files. How
were you creating the file? What did you change it to which broke
things?


From: Leo Davidson on
On Aug 9, 11:43 am, "R.Wieser" <addr...(a)not.available> wrote:
> Hello Leo,
>
> > Windows does not impose any extension requirements on temp files.
>
> Yes, it does.  Not on "temporary files" in general, but certainly on a
> "temporary file*name*" generated by the GetTempFileName function in
> Kernel32.

Right, but you don't have to use GetTempFileName to create a temp
file.

If the problem is only caused by a difference in how GetTempFileName
creates the file vs how your CreateFile call does so, maybe using
Process Monitor to see what gets called will help. It usually shows
you the underlying file-creation calls and their flags, although I
have not checked what happens with GetTempFileName.

Maybe you could also use GetTempFileName and then rename the file
after creation.

Re FILE_FLAG_DELETE_ON_CLOSE, it definitely works (I use it myself for
auto-delete temp-files), although you have to ensure anything opening
the file allows FILE_SHARE_DELETE and the semantics of when the file
becomes unavailable to new openers (I think when the original handle
is closed) and deleted (I think when the last handle is closed) may
not be what you need. (I may be wrong on those details.)
From: Paul N on
On 8 Aug, 19:09, "R.Wieser" <addr...(a)not.available> wrote:
> And that brings me to my actual question : Is there a way to start an
> application with some data that is only there for that app, and disappears
> (preferrably handled by the OS) when the app does not need it anymore.

Just an idea, but - is it possible to use the drag and drop mechanism
to do this?