OhadM
OhadM

Reputation: 4803

Parse .ini file from resource during runtime using C++/boost

I have an .ini file which is located inside the resource as an RCDATA. I load it from the resource during runtime, and I am able to get it as a very long string.

I am interested of loading the .ini file (from the resource at runtime) and parse it as an .ini file using Boost or Win32 API but the question is how do I do it ?

It seems that it is possible of doing such thing using QT.

I have tried loading the resource file and assigning read_ini() the binary data/string file but it doesn't iterate over it afterwards.

Is it possible of doing such thing ?

Code snip:

HRSRC myResource = FindResource(NULL, MAKEINTRESOURCE(101), RT_RCDATA);
unsigned int myResourceSize = SizeofResource(NULL, myResource);
HGLOBAL myResourceData = LoadResource(NULL, myResource);
char* pMyBinaryData = (char*)LockResource(myResourceData);
char *text = (char*)malloc(myResourceSize + 1);
memcpy(text, pMyBinaryData, myResourceSize);
text[myResourceSize] = 0;//last char array is null
FreeResource(myResourceData);

The way I extract the text inside the .txt/.ini file.

Upvotes: 1

Views: 347

Answers (1)

sehe
sehe

Reputation: 393174

I suppose you might be looking for

std::istringstream iss(the_large_string_value);

boost::property_tree::ptree pt;
boost::property_tree::read_ini(iss, pt);

Of course, you can read (really large) resources as a stream. Boost IOstreams has an array_source that can help there.

The simplest thing here would be

std::string the_large_resource_string_value(pMyBinaryData, myResourceSize);

Upvotes: 1

Related Questions