Reputation: 362
Whats the easiest way to load a raw file from a resource in C++ using the WinAPI? I just want to load the file(for example .txt) into a char array. I searched on the internet but I couldn't really find something useful and simple like LoadStringFromFile(int idFromResource, char* buffer).
Upvotes: 3
Views: 1352
Reputation: 612784
Take the following steps:
FindResource
passing module handle, resource type and resource name. This yields a HRSRC
. Note that if you have a resource ID rather than a resource name, use MAKEINTRESOURCE
to convert.LoadResource
passing the HRSRC
from the previous step. This yields an HGLOBAL
.LockResource
passing the HGLOBAL
. This yields a pointer to the first byte of the resource.SizeofResource
passing the HRSRC
to find the size of the resource.Upvotes: 5