I am trying to use the Win32 FindResource() function to load an embedded resource into a buffer. I am adding a resource compile time, in Visual Studio 2015 IDE:
As you can see using a PE editor like CFFexplorer or ResHacker, resource gets added correctly:

The problem comes when I try to use the FindResource() function to load it on runtime, at the start of a DLL project:
INT WINAPI DllMain( HINSTANCE hInstDLL, DWORD dwReason, LPVOID lpReserved )
{
HRSRC ResLocation = 0;
switch( dwReason )
{
case DLL_PROCESS_ATTACH:
// Show debug console
AllocConsole();
freopen("CONOUT$", "w", stdout);
//Locate our resource
ResLocation = FindResource(hInstDLL, "RESFILE", "RESFILE");
// FindResource returns NULL with error 1813: ERROR_RESOURCE_TYPE_NOT_FOUND
printf("TEST RESULT: reslocation: %i error %i\n", ResLocation, GetLastError());
StartProc();
break;
case DLL_PROCESS_DETACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
}
return 1;
}
FindResource returns NULL with error 1813: ERROR_RESOURCE_TYPE_NOT_FOUND. Any idea on why it doesn't manage to load the resource? Thank you

DllMain!AllocConsoleis an obvious no-no. - Cody GrayDllMain, just to be on the safe side. The documentation contains a list of things that are expressly forbidden, but calling any complex APIs or third-party code is inherently tricky because you have no way of knowing what they do. The goal is to keepDllMainan empty stub, using lazy initialization for everything. If you absolutely need to do more, have your DLL provide and export anInitialize(or similar) function that applications would call. The Windows libraries all do this, like COM, GDI+, etc. - Cody Gray