Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


How do I include a file, then save the file to c:\windows

Posted on 1999-08-20
Medium Priority
Last Modified: 2010-04-02
I need to update a .vxd file on many machines.
How can I take the updated file and include it in my c++ program, than run the program so that it copies and saves that file to C:\windows\system

Thanks for any help
Question by:pote
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

Expert Comment

ID: 1202953
What do you mean by INCLUDE?
LVL 22

Expert Comment

ID: 1202954
Your can write an "install" program that copies the file the the system directory using CopyFile().  

If the file you want to copy over is open by the system, it will fail.  In that case you can use MoveFileEx() to copy the file on an NT machine.  The documenation for MoveFileEx() explains how to achieve this on a windows 9x machine.

Author Comment

ID: 1202955
By include I mean to distribute a new file, and have the exe rogram copy that file to the windows dir.
How do I reference the new file from within the C++ program, or where do I store the file, and how do I tell the program to copy the file to windows?

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.

LVL 22

Expert Comment

ID: 1202956
Just store the new file somewhere on the instillation disk.  One common way to handle this is to just place the new file in the same directory as the installation program.  Then the instillation program can use GetModuleFileName() to get the path to itself, and then it can use this to get the path to the file to be installed.

Expert Comment

ID: 1202957
Are you trying to actually include the file in the EXE as data, then create the new VXD in the C:\Windows\System directory and and write out the data to the new file?  That way you can distribute one file.

If so, this is possible by converting the original VXD file to a CPP file in hex:

unsigned char sVXD[] = {0xFE, 0xBE, ...};

Then create the file and write sVXD[] out to it.

You'd have to write (or find) a small utility program that converts the VXD to a CPP though.

Is this what you're asking for?
LVL 22

Expert Comment

ID: 1202958
For that sort of approach you could just place the program to be installed inside the installation program as a binary resource.

Expert Comment

ID: 1202959
I am working with a similar situation that might clear up what pote is trying to do.  I would like to Import a binary file into the VS C++ 6.0 project Resource area so it is included in my executable.  Then, I would like to extract that file from the Resource area and save the file to a directory on the user's machine.  I don't know how to extract the file from the Resource area of the executable and save the file to the user's machine.  

pote, is this similare to what you are trying to accomplish?

Accepted Solution

cpopin earned 60 total points
ID: 1202960
What I did was create a custom "EXECUTEABLE" type of resource named "TEST.EXE" and imported the file.  Then I used the following code to write it back out:

    const char sFileName[] = "TEST.EXE";
    HRSRC hrExe = FindResource(NULL, sFileName, "EXECUTEABLE");
    DWORD cExe = SizeofResource(NULL, hrExe);
    HGLOBAL hExe = LoadResource(NULL, hrExe);
    char *spExe = (char *)LockResource(hExe);
    CFile fExe;
    CFileException e;
    if (!fExe.Open(sFileName, CFile::modeCreate | CFile::modeWrite, &e)) {
#ifdef _DEBUG
        afxDump << "File could not be opened " << e.m_cause << "\n";
    fExe.Write(spExe, cExe);

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

722 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