B
Bonj
can you embed a resource into a static libary?
I'm using a custom binary resource specified as a .bin file in the .rc file
of the static library project I've got. I use FindResource, LoadResource,
LockResource to get the resource. However FindResource is returning null. If
I use exactly the same code to retrieve a resource out of the resource of
the console application used to test the static library, then it works
perfectly. I can't see how the resource isn't being compiled into the static
library, as its size would seem to indicate that it has. It's using
GetModuleHandle(NULL) in order to get the process handle.
Any idea what could be wrong?
This is the code in the static library:
BOOL loaddata()
{
HMODULE hModule = GetModuleHandle(NULL);
HRSRC hRsrc = FindResource(hModule, MAKEINTRESOURCE(IDR_NODES), "NODES");
if(hRsrc != NULL)
{
HGLOBAL hGMem = LoadResource(hModule, hRsrc);
if(hGMem != NULL)
{
ressize = SizeofResource(hModule, hRsrc);
resdata = (NODE*)LockResource(hGMem);
if(ressize > 0) return TRUE;
else FreeResource(hGMem);
}
}
return FALSE;
}
in which hRsrc goes to NULL.
The code that works fine in the console application used to test it goes
like this:
HMODULE hModule = GetModuleHandle(NULL);
HRSRC hRsrc = FindResource(hModule, MAKEINTRESOURCE(IDR_BIN11), "BIN1");
HGLOBAL hGMem = LoadResource(hModule, hRsrc);
LPBYTE lpData = (LPBYTE)LockResource(hGMem);
DWORD dwSize = SizeofResource(hModule, hRsrc);
FreeResource(hGMem);
and it works fine.
I'm using a custom binary resource specified as a .bin file in the .rc file
of the static library project I've got. I use FindResource, LoadResource,
LockResource to get the resource. However FindResource is returning null. If
I use exactly the same code to retrieve a resource out of the resource of
the console application used to test the static library, then it works
perfectly. I can't see how the resource isn't being compiled into the static
library, as its size would seem to indicate that it has. It's using
GetModuleHandle(NULL) in order to get the process handle.
Any idea what could be wrong?
This is the code in the static library:
BOOL loaddata()
{
HMODULE hModule = GetModuleHandle(NULL);
HRSRC hRsrc = FindResource(hModule, MAKEINTRESOURCE(IDR_NODES), "NODES");
if(hRsrc != NULL)
{
HGLOBAL hGMem = LoadResource(hModule, hRsrc);
if(hGMem != NULL)
{
ressize = SizeofResource(hModule, hRsrc);
resdata = (NODE*)LockResource(hGMem);
if(ressize > 0) return TRUE;
else FreeResource(hGMem);
}
}
return FALSE;
}
in which hRsrc goes to NULL.
The code that works fine in the console application used to test it goes
like this:
HMODULE hModule = GetModuleHandle(NULL);
HRSRC hRsrc = FindResource(hModule, MAKEINTRESOURCE(IDR_BIN11), "BIN1");
HGLOBAL hGMem = LoadResource(hModule, hRsrc);
LPBYTE lpData = (LPBYTE)LockResource(hGMem);
DWORD dwSize = SizeofResource(hModule, hRsrc);
FreeResource(hGMem);
and it works fine.