I'm using SFML with C++ in VS2012. In debug console i have error "failed to load image from memory, no data provided".
My main.cpp
#include <iostream>
#include "Test.h"
#include "resource.h"
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
using namespace std;
sf::Image LoadImageFromResource(const std::string& name)
{
HRSRC rsrcData = FindResource(NULL, name.c_str(), RT_RCDATA);
DWORD rsrcDataSize = SizeofResource(NULL, rsrcData);
HGLOBAL grsrcData = LoadResource(NULL, rsrcData);
LPVOID firstByte = LockResource(grsrcData);
sf::Image image;
image.loadFromMemory(firstByte, rsrcDataSize);
return image;
}
int main()
{
sf::Image SpriteSheetWalkRes = LoadImageFromResource("IDB_PNG1");
}
My Resource.rc
#define APSTUDIO_READONLY_SYMBOLS
#include "afxres.h"
#undef APSTUDIO_READONLY_SYMBOLS
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS)
LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT
#ifdef APSTUDIO_INVOKED
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif
IDB_PNG1 RCDATA "F:\\(...)\\test_player.png"
#endif
#ifndef APSTUDIO_INVOKED
#endif
My resource.h
#define IDB_PNG1 101
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 102
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif