Thread: JPEG Resource

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

    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,

    // now get a handle to the resource
    if ((hResource = LoadResource(hinstance, hResInfo)) == 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
    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

  3. #3
    train spotter
    Join Date
    Aug 2001
    near a computer

    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, 07:12 PM
  2. CreateProcess with Resource of executable, not the Filename
    By Ktulu in forum Windows Programming
    Replies: 4
    Last Post: 11-04-2006, 01: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, 02:08 PM
  5. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 10:52 AM