SizeofResource not returning right size

This is a discussion on SizeofResource not returning right size within the Windows Programming forums, part of the Platform Specific Boards category; Im trying to lock and write the icon resource, that is in module itself, to a file. Its an icon.ico ...

  1. #1
    Registered User
    Join Date
    Dec 2007
    Location
    France
    Posts
    747

    SizeofResource not returning right size

    Im trying to lock and write the icon resource, that is in module itself, to a file.
    Its an icon.ico file 16x16 with size 1150 bytes and SizeofResource returns only 20 bytes.

    GetLastError returns "The operation completed successfully". and the icon is displayed as expected.

    resource.rc
    Code:
    #define IDI_MYICON   101
    
    IDI_MYICON   ICON  "myicon.ico"
    The function:
    Code:
    void Resource()
    {
        FILE *file;
        HRSRC hRes = NULL;
        HGLOBAL hResLoaded;
        LPVOID lpResLock = NULL;
        char* cbuf;
        DWORD sizeOfRes;
        int i;
        hRes = FindResource(NULL,
                                MAKEINTRESOURCE(IDI_MYICON),
                                RT_GROUP_ICON);
        
        if(hRes != NULL)
        {
            hResLoaded = LoadResource(NULL, hRes);
    
            if(hResLoaded != NULL)
            {
                sizeOfRes = SizeofResource(NULL, hRes);
                cout << "Size = "<< sizeOfRes << endl;
                cbuf = (char*) calloc (sizeOfRes, sizeof(char));
                strcpy(cbuf,(char*)LockResource(hResLoaded));
    
                if(sizeOfRes != 0)
                {
                    file = fopen("myfile.txt", "wb");
                    if(file != NULL)
                    {
                        for(i = 0; i < sizeOfRes; i++)
                        {
                            fwrite(&cbuf[i],sizeof(char),1,file);
                        }
                        fclose(file);
                    }
                }
            }
            free(cbuf);
            UnlockResource(hResLoaded);
            FreeResource(hResLoaded);
        }
    }
    Last edited by Ducky; 10-28-2010 at 07:11 AM.
    Compiler MSVC++ 2010 with Code::Blocks.

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    I think you are getting the size of a GRPICONDIR struct (holding an array of pointers to the image data you want).

    Have a read here.

    Icons
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Registered User
    Join Date
    Dec 2007
    Location
    France
    Posts
    747
    Thank you very much Novocain!
    Compiler MSVC++ 2010 with Code::Blocks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with arrays
    By chilledmilk in forum C++ Programming
    Replies: 1
    Last Post: 05-06-2010, 10:32 PM
  2. Heapsort
    By xENGINEERx in forum C Programming
    Replies: 2
    Last Post: 03-30-2008, 07:17 PM
  3. Generic heapsort
    By Sephiroth1109 in forum C Programming
    Replies: 15
    Last Post: 12-07-2007, 05:14 PM
  4. Invalid conversion from 'void*' to 'BYTE' help
    By bikr692002 in forum C++ Programming
    Replies: 9
    Last Post: 02-22-2006, 10:27 AM
  5. An exercise in optimization
    By Prelude in forum Contests Board
    Replies: 10
    Last Post: 04-29-2005, 03:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21