ifstream from resource

Posted on 2004-11-19
Last Modified: 2009-07-29
Need to get ifstream from resource.
I have this:

int LoadResource (UINT res, char * szres)
  HINSTANCE hInst = AfxGetResourceHandle();
  HRSRC hRsrc = ::FindResource(hInst, MAKEINTRESOURCE(res), szres);
  BYTE* lpRsrc = (BYTE*)LoadResource(hInst, hRsrc);

How do I get ifstream from this?
Question by:jd9288
    LVL 86

    Accepted Solution

    Without writing your own 'ifstream' implementation, the only way would be to save the bytes to a file and open that again, which for sure is cumbersome. Would 'CreateStreamOnHGlobal()' help?

    Author Comment

    jkr, I figured it out.
    I needed to load animated GIF file from resource, and I had the code
    how to load it from disk (WINIMAGE.CPP by Juan Soulie), so I just used memcpy on the byte array to manually
    do what the ifstream does.

    I wanted to know if there was an easy way out, and you answered that.


    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
    What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
    The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
    The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now