Holding a file as a resource in a C++ .exe

  • Thread starter Thread starter Steve McLellan
  • Start date Start date
S

Steve McLellan

Hi,

Many apologies if this is the wrong group; if anyone can suggest a better
one please do.

I need to write a very small C++ (Win32, not .NET) application that will
essentially do a file copy after running some code to decide where to copy
the file to. Ideally I'd like to contain the file inside the EXE so that
from the user's point of view they download one file and it does what it's
supposed to do. I could equally do the same with a zip file containing the
file and a batch file to do the copy.

I can't find any information about whether it's possible to include a file
as a resource, and be able to treat it as a file from within the
application. Has anyone got any ideas?

Thanks,

Steve
 
I can't find any information about whether it's possible to include a file
as a resource

It is possible Steve, see "User-Defined Resource" in MSDN.
and be able to treat it as a file from within the
application.

You'll need to treat it as a stream of data.

Dave
 
David Lowndes said:
It is possible Steve, see "User-Defined Resource" in MSDN.


You'll need to treat it as a stream of data.

Hi David,

OK, thanks, I'll check that out.

Steve
 
DL> It is possible Steve, see "User-Defined Resource" in MSDN.DL> You'll need to treat it as a stream of data.

You could make use of the following functions to extract it at runtime:

FindResource
LoadResource
LockResource
SizeofResource

(the first three should be used in the given sequence)

Also, a file can be addressed via the res:// protocol from the browser.
 
Serge Baltic said:
DL> It is possible Steve, see "User-Defined Resource" in MSDN.
DL> You'll need to treat it as a stream of data.

You could make use of the following functions to extract it at runtime:

FindResource
LoadResource
LockResource
SizeofResource

(the first three should be used in the given sequence)

Also, a file can be addressed via the res:// protocol from the browser.
Hi Serge,

Thanks for the reply. I'd prefer not to read it at all if possible - the
application doesn't need to read the contents of the file, just be able to
copy it to a local disk location. But I guess writing it as a stream is a
reasonable solution and certainly seems to be much easier looking at the
API.

Thanks again,

Steve
 
Back
Top