WindowsResourceStream.h#

Parent directory (Windows)

A Stream implementation used to access Windows embedded resources.

Includes#

Namespaces#

Classes#

Defines#

Source Code#

#pragma once
#include "PVRCore/stream/BufferStream.h"
#include <string>
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <Windows.h>

namespace pvr {
class WindowsResourceStream : public BufferStream
{
public:
    WindowsResourceStream(const std::string& resourceName, bool errorOnNotFound = true) : BufferStream(resourceName)
    {
        _isReadable = false;
        _isWritable = false;
        _isRandomAccess = false;

        // Find a handle to the resource
        HRSRC hR = FindResource(GetModuleHandle(NULL), resourceName.c_str(), RT_RCDATA);

        if (!hR)
        {
            if (errorOnNotFound) { throw FileNotFoundError(resourceName); }
            return;
        }
        // Get a global handle to the resource data, which allows us to query the data pointer
        HGLOBAL hG = LoadResource(NULL, hR);

        if (!hG)
        {
            if (errorOnNotFound) { throw FileNotFoundError(resourceName); }
            return;
        }
        // Get the data pointer itself. NB: Does not actually lock anything.
        _originalData = LockResource(hG);
        _currentPointer = _originalData;
        _bufferSize = SizeofResource(NULL, hR);
        _isReadable = true;
        _isWritable = false;
        _isRandomAccess = true;
        return;
    }
}; // namespace pvr
} // namespace pvr