michalo2882
michalo2882

Reputation: 27

Win32, Resource file, loading into memory

This is my test.rc file:

shader.hlsl shaders "HLSL\\shader.hlsl"

I know it doesn't look like usual rc file but whe I use function like this.

D3DX11CompileFromResource(handle, L"shader.hlsl", NULL, NULL, NULL, "VS", "vs_4_0", 0, 0, NULL, &s, &err, &hr);

It works perfectly, but I want to load this file into memory. Tell me please how to do it, because I'm lack of ideas now. I tried with something like that.

HRSRC hSrc = FindResource(GetModuleHandle(0), L"shader.hlsl", L"shaders");

but without success.

EDIT:

FindResource() returns NULL!

Upvotes: 1

Views: 1942

Answers (2)

michalo2882
michalo2882

Reputation: 27

Problem partially solved. In fact, I had a problem with resources of type "rcdata", not "shaders". I put the second as an example but didn't check it (I'm really sorry, that I wasted your time). Seems like every type name except "rcdata" works. But why...?

EDIT: Problem fully solved. I just need to use RT_RCDATA as type name. Seems like "rcdata" type is a standard name.

Upvotes: 0

Serge Wautier
Serge Wautier

Reputation: 21878

You're on the right track: You need to use a sequence of FindResource / LoadResource / LockResource :

HMODULE hModule = GetModuleHandle(NULL);
HRSRC hRes = FindResource(hModule, L"shader.hlsl", L"shaders"); 
HGLOBAL hMem = LoadResource(hModule, hRes);
LPVOID lpResource = LockResource(hMem);

DWORD size = SizeofResource(hModule, hRes);

lpResource is a pointer to your resource. size is the size in bytes of the memory block. Of course, don't forget to call FreeResource(hMem) when you're done.

Upvotes: 1

Related Questions