Click here to Skip to main content
13,000,636 members (57,156 online)
Rate this:
Please Sign up or sign in to vote.
See more:

I improved my question in a sequence what i am doing in the project.

Just tell me what to be removed from below lines of sentences.

1) Project name is FaceRecognition.

2) Project is having dependency of .xml, .dll, .jpg.

3) .xml files are:
1) haarcascade_frontalface_alt2.xml
2) haarcascade_mcs_lefteye.xml and three more files.

4) .dll files are:
2)cvaux210.dll and 8 more dll files.

5) .jpg files are:
1) down.jpg
2) normal.jpg and 4 more jpg files.

6) all these .* files are added to the resource files of the preoject in solution explorer.

7) and coming to .rc file here i am adding the complete path of these files like:

IDR_XML1 FILE C:\\FaceRecognition\\FaceRecognition\\haarcascade_frontalface_alt2.xml"
IDR_XML2 FILE "C:\\FaceRecognition\\FaceRecognition\\haarcascade_mcs_lefteye.xml"
IDR_DLL1 FILE "C:\\FaceRecognition\\FaceRecognition\\cv210.dll"
IDR_DLL2 FILE "C:\\FaceRecognition\\FaceRecognition\\cvaux210.dll"
IDR_JPG1 FILE "C:\\FaceRecognition\\FaceRecognition\\down.jpg"
IDR_JPG2 FILE "C:\\FaceRecognition\\FaceRecognition\\normal.jpg"

8) and in the code i am assigning these .xml and .jpg to variables, there also i am giving

the full path.

9) the Last is createfilefromresource() function where should i write this function in the project and what parameters should i pass to the function.

this is the process i am doing in the project to merge all files with an .exe.

From this plz mention what i am doing right and what i am doing wrong.

Thank u very very much.
Posted 14-Jan-13 22:32pm
Kumar 091.2K
Updated 17-Jan-13 20:23pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

I do this in some of my code.

You can embed the data into resources of the .exe file. To do this, all of the "to be embedded" files need to exist when the .exe is built. Add the files as resources to the enclosing .exe file (you asked about C++ and MFC; the process is a little different for .NET). To do this, add each file as a line item in the .rc or .rc2 file, just as you do with bitmaps and icons:

// Icon
IDR_MAINFRAME           ICON                 "blahblah\\icons\\blahblah.ico"
IDR_FILE_RELEASENOTES   HTML                 "blahblah\\text\\blahblah_releasenotes.htm"
IDR_FILE_PARAM          FILE                 "blahblah\\paramdata\\PARAMS.XML"
IDR_FILE_TEST           FILE                 "blahblah\\paramdata\\TESTDATA.DAT"

Here is the code I use to extract the data to a file (when my program runs):

bool CreateFileFromResource(char const* sFilename, HMODULE hInstance, WORD resourceID)
    bool bRetval = false;
    HANDLE hFile = CreateFile(sFilename, GENERIC_READ | GENERIC_WRITE,
        //if(NULL == hInstance)
        //    hInstance = AfxGetResourceHandle();
        HRSRC hResource = FindResource(hInstance, MAKEINTRESOURCE(resourceID), "FILE");
            HGLOBAL hFileResource = LoadResource(hInstance, hResource);
                LPVOID lpFile = LockResource(hFileResource);
                    DWORD dwSize = SizeofResource(hInstance, hResource);
                    HANDLE hFilemap = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0, dwSize, NULL);
                    LPVOID lpBaseAddress = MapViewOfFile(hFilemap, FILE_MAP_WRITE, 0, 0, 0);
                    CopyMemory(lpBaseAddress, lpFile, dwSize);
                    bRetval = true;
    return bRetval;

I also have code to extract the contents of an embedded resource (usually xml) into a string or a DOM which I'm sure you can figure out from the above.

As I said above, this code works in a native C++/MFC environment (ie. if you build a RES file). The concept is the same but with different details in .NET (ie. if you use a .RESX file).
Kumar 09 15-Jan-13 21:37pm
when i give the .xml and .jpg in .rc file like this for .xml

and for .jpg

IDR_JPG1 GIFF "res\\image1.jpg"
IDR_JPG2 GIFF "res\\image2.jpg"

and compile and build and when i run the .exe it is unable to display the .jpg file on the dialog and giving an error unable to load the file1.xml file.

all these .xml and .jpg files are stored in res folder in the application.

in the code i hard coded for the .xml and .jpg files as "res\\file1.xml" and "res\\image1.jpg".

is it the right way or not.

H.Brydon 16-Jan-13 10:09am
I think the problem is use of "GIFF" - this is not a valid resource type. The .jpg files should be "FILE". Same again for "*.dll", "*.exe" etc.

The valid resource types are BMP, ICON, FILE, HTML and several others.
Kumar 09 16-Jan-13 20:56pm
Hello Brydon,
i tried the same way as u mentioned above like this
IDR_JPG1 FILE "image1.jpg"
IDR_JPG2 FILE "image2.jpg"
IDR_DLL1 FILE "cv210.dll"
IDR_DLL2 FILE "cvaux210.dll"
.... etc.
but when i run application from application folder its giving error "not responding" and application getting struck.

when i copy the dependency files like .dll's, .xml's and .jpg in to the folder where exe exists its running perfectly.

where i am going wrong i couldn't understand.

As i am using Visual Studio 2010 vc++ and opencv dll('s) and xml('s) files in the application.
H.Brydon 17-Jan-13 13:32pm
When the resource file is being built, the build process needs to be able to find the filespec that you give in each of the above lines. If image1.jpg or cv210.dll are in a different directory for example, you need to provide path information. See the example in my original code sample above:

IDR_FILE_TEST FILE "blahblah\\paramdata\\TESTDATA.DAT"

In other words the "blahblah\\paramdata\\" stuff is important.
Kumar 09 17-Jan-13 21:19pm
Is it compulsory to write a CreateFileFromResource() function which you mentioned above comment. If yes in which class we should write this function.

one more query, if i do same thing whatever we discussed above and i copy the .exe and run in other computer whether the .exe will run correctly without any problems. Because i tried the same way but the exe is not responding at all (dependency files are not found as we mentioned the path in the resource file).
H.Brydon 18-Jan-13 0:03am
I think there is some confusion about how the pieces fit together. My assumption was that you have files abc.exe, abc.xml, abc.jpg, abc.dll (perhaps others) and you want to package these together into an exe file "container.exe". The code I presented above (CreateFileFromResource() and the resource info) gets built into container.exe. You can send container.exe to the 'other' machine and execute it there. When it runs, it extracts the "abc.*" files by calling CreateFileFromResource() with the appropriate parameters.

If you want to embed the XML or jpg files into abc.exe you can do this with the same technique (in abc.rc or abc.rc2), but not the DLL (if abc.dll is linked from abc.exe).

If this is still confusing to you, maybe provide more details, including some of your actual file names.
Kumar 09 18-Jan-13 1:14am
Thank u very much. one last question where should i add this createfilefromresource() funtion in the project. what parameters should i pass to it.

**Please see above i improved my qestion.
H.Brydon 18-Jan-13 17:23pm
You would call CreateFileFromResource() in your "container.exe" when you want to expand the resources out into files. For example:

if( files need to be created...)
CreateFileFromResource("somewhere\\File1.XML", GetModuleHandle(0), IDR_FILE_XML1);
// etc. for the other files
Kumar 09 19-Jan-13 1:42am
In CreateFileFromResource() when i run the application its giving an error at the HMODULE hInstance and HRSRC hResource.
H.Brydon 19-Jan-13 13:07pm
Sorry - used 0 instead of GetModuleHandle(0) - see corrected source in previous info.
Kumar 09 21-Jan-13 20:27pm
Thank you very much Brydon. Its working fine.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You can create a compressed archive using something like WinZip or WinRar. However, a better choice would be to create a program installer using one of the tools available; Google will find you some suggestions.
Kumar 09 15-Jan-13 5:17am
i mean to say, i want to merge all the .dll, .xml, .png and .exe file in to one single .exe file, so that i can run the exe in other system without dependencies of this files.
Richard MacCutchan 15-Jan-13 5:40am
In that case do not use a DLL but create a static library so it will be linked in to the executable. The other files can be added as resources.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170624.1 | Last Updated 18 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100