문제

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).

도움이 되었습니까?

해결책

Take the following steps:

  1. Call 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.
  2. Call LoadResource passing the HRSRC from the previous step. This yields an HGLOBAL.
  3. Call LockResource passing the HGLOBAL. This yields a pointer to the first byte of the resource.
  4. Call SizeofResource passing the HRSRC to find the size of the resource.
  5. Copy the content of the resource into your buffer using the pointer retrieved from step 3, and the size retrieved from step 4.
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top