Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

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:
1)cv210.dll
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
Updated 17-Jan-13 20:23pm
v5

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"

/////////////////////////////////////////////////////////////////////////////
//
// HTML

IDR_FILE_RELEASENOTES   HTML                 "blahblah\\text\\blahblah_releasenotes.htm"

/////////////////////////////////////////////////////////////////////////////
//
// FILE

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):

C++
bool CreateFileFromResource(char const* sFilename, HMODULE hInstance, WORD resourceID)
{
    bool bRetval = false;
    HANDLE hFile = CreateFile(sFilename, GENERIC_READ | GENERIC_WRITE,
        0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    _ASSERTE(hFile);
    if(hFile)
    {
        _ASSERTE(hInstance);
        //if(NULL == hInstance)
        //    hInstance = AfxGetResourceHandle();

        HRSRC hResource = FindResource(hInstance, MAKEINTRESOURCE(resourceID), "FILE");
        _ASSERTE(hResource);
        if(hResource)
        {
            HGLOBAL hFileResource = LoadResource(hInstance, hResource);
            _ASSERTE(hFileResource);
            if(hFileResource)
            {
                LPVOID lpFile = LockResource(hFileResource);
                _ASSERTE(lpFile);
                if(lpFile)
                {
                    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);

                    UnmapViewOfFile(lpBaseAddress);
                    CloseHandle(hFilemap);
                    bRetval = true;
                }
            }
        }
        CloseHandle(hFile);
    }
    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).
 
Share this answer
 
Comments
Kumar 09 15-Jan-13 21:37pm    
when i give the .xml and .jpg in .rc file like this for .xml
IDR_FILE_XML1 FILE "res\\File1.XML"
IDR_FILE_XML2 FILE "res\\File2.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_FILE_XML1 FILE "File1.XML"
IDR_FILE_XML2 FILE "File2.XML"
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).
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.
 
Share this answer
 
Comments
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900