I've stuck into a strange problem. The same code works perfect outside of dll but not working inside dll.
Code inside dll. Errors and nulls:
// 1813 here
HRSRC hrsrc = FindResourceW(hInstance,
MAKEINTRESOURCE(IDD_DIALOG1),
RT_DIALOG);
// NULL here.
HGLOBAL hg = LoadResource(hInstance, hrsrc);
Outside dll, all fine:
// Pointer here, all fine
HRSRC hrsrc = FindResourceW(hInstance,
MAKEINTRESOURCE(IDD_DIALOG1),
RT_DIALOG);
// Pointer here.
HGLOBAL hg = LoadResource(hInstance, hrsrc);
The resource DOES exist inside the dll resources, I checked and even recreated my resource files. And it does compile in both cases, no Symbol not resolved
errors.
And yes, I pass hInstance
parameter to dll function. double* arr = ShowXMinXMaxDialogDisableParent(hInst, hWnd, xMin, xMax);
It's not null (at least while debugging). I initialize hInstance
inside WinMain function, so it's correct:
// main function
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
hInst = hInstance;
I have no ideas what's wrong. hInstance is wrong? Obvious, I checked it with debugger. No changes, the value is absolutely the same.
Solution:
Needed to use the DLL instance, not app instance. I can get it in DllMain dll function.
You are passing the wrong HINSTANCE
to the FindResource()
and LoadResource()
functions. You are passing the HINSTANCE
from your WinMain()
function, which is correct only for resources located in the EXE file.
You want to load resources from the DLL, so you must pass the HINSTANCE
of the DLL, which you get in your DllMain()
function instead.