JPEG Resource

This is a discussion on JPEG Resource within the Windows Programming forums, part of the Platform Specific Boards category; I have a JPG file that I would like to load as a resource and save it as a file ...

  1. #1
    Registered User dragunsflame's Avatar
    Join Date
    Jan 2003
    Posts
    8

    JPEG Resource

    I have a JPG file that I would like to load as a resource and save it as a file on the hard disk. What I'm doing now is saving the picture as a custom user data and outputting it as a file.

    The problem i'm having is loading the jpg data from the resource. Currently, i'm using this function:

    UCHAR* LoadCustomResource(int resID, HINSTANCE hinstance)
    {
    HRSRC hResInfo;
    HGLOBAL hResource;

    // first find the resource info block
    if ((hResInfo = FindResource(hinstance,
    MAKEINTRESOURCE(resID),
    "CUSTOMRESOURCETYPE")) == NULL)
    return(NULL);

    // now get a handle to the resource
    if ((hResource = LoadResource(hinstance, hResInfo)) == NULL)
    return(NULL);

    // finally get and return a pointer to the resource
    return ((UCHAR*)LockResource(hResource));
    }

    I'm then writing the data using this line:

    ofs1.write( (char*) LoadCustomResource(IDR_JPG1, hInstance), sizeof(MAKEINTRESOURCE(IDR_JPG1)) );

    I'm so lost, as when i run the program it gives me an error after opening the file to write to. Any suggestions?

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    68
    I am assuming that you are using OutputStream, write function

    basic_ostream& write(const E *s, streamsize n);

    first thing did you try to check if the data is in the buffer before you are writing it. If so then is then are you writing the JPEG hearder before writing the buffer data.

    Let me know
    Pratik

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,855
    >>sizeof(MAKEINTRESOURCE(IDR_JPG1))

    What does this return as a size?
    "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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sorting out a resource manager
    By psychopath in forum Game Programming
    Replies: 1
    Last Post: 11-10-2008, 06:12 PM
  2. CreateProcess with Resource of executable, not the Filename
    By Ktulu in forum Windows Programming
    Replies: 4
    Last Post: 11-04-2006, 12:07 AM
  3. JPEG from resource with GDI+
    By lord mazdak in forum Windows Programming
    Replies: 4
    Last Post: 04-05-2006, 04:23 PM
  4. resource problem/question
    By stallion in forum Windows Programming
    Replies: 4
    Last Post: 01-29-2003, 01:08 PM
  5. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 09:52 AM

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