Finding/Loading resources
-
Hi all, I'm trying to find and load a resource from another application. Here's the code I'm using: HINSTANCE hToDLL; HRSRC hsrc; hsrc = FindResource(GetModuleHandle(app),icon,RT_ICON); where app = "someapp.exe" and icon = "IDI_ICON3" This ALWAYS returns a NULL pointer, so it's always failing and the GetLastError always gives me a: 1813 The specified resource type cannot be found in the image file. ERROR_RESOURCE_TYPE_NOT_FOUND Now I know the resource exists in the application I'm trying to get at, so what am I doing wrong?? Do I need to call LoadLibrary first? I don't think I should have to. Any insights, help, suggestions, comments are greatly appreciated. Thanks! Dan
The GetModuleHandle() function retrieves a module handle for the specified module if the file has been mapped into the address space of the calling process. Had you checked the return value of it, rather than immediately calling FindResource(), this might have been evident.
-
The GetModuleHandle() function retrieves a module handle for the specified module if the file has been mapped into the address space of the calling process. Had you checked the return value of it, rather than immediately calling FindResource(), this might have been evident.
DavidCrow wrote: The GetModuleHandle() function retrieves a module handle for the specified module if the file has been mapped into the address space of the calling process. Had you checked the return value of it, rather than immediately calling FindResource(), this might have been evident. Gotcha, I understand now, but then what do I need to do to map the file into the address space? Call LoadResource? Thanks! Dan
-
DavidCrow wrote: The GetModuleHandle() function retrieves a module handle for the specified module if the file has been mapped into the address space of the calling process. Had you checked the return value of it, rather than immediately calling FindResource(), this might have been evident. Gotcha, I understand now, but then what do I need to do to map the file into the address space? Call LoadResource? Thanks! Dan
HMODULE hModule;
HRSRC hResource;hModule = LoadLibrary(...);
if (NULL != hModule)
{
hResource = FindResource(hModule, ...);
if (NULL != hResource)
{
LoadResource(hResource, ...);
}FreeLibrary(hModule);
}
-
HMODULE hModule;
HRSRC hResource;hModule = LoadLibrary(...);
if (NULL != hModule)
{
hResource = FindResource(hModule, ...);
if (NULL != hResource)
{
LoadResource(hResource, ...);
}FreeLibrary(hModule);
}
-
Since the module is an EXE, you may want to use the LoadLibraryEx() function instead, passing LOAD_LIBRARY_AS_ DATAFILE for the Flags parameter. This will prevent any calls to unresolved externals (like DllMain) and prevent the loader from loading any dependent dlls that the EXE imports.
-
Since the module is an EXE, you may want to use the LoadLibraryEx() function instead, passing LOAD_LIBRARY_AS_ DATAFILE for the Flags parameter. This will prevent any calls to unresolved externals (like DllMain) and prevent the loader from loading any dependent dlls that the EXE imports.
Ok, I'm further in my understanding, but still no further in a solution. Here's what I have now: HMODULE hModule; HRSRC hResource; sprintf(buff,"%s.exe",app); hModule = LoadLibraryEx(buff,NULL,LOAD_LIBRARY_AS_DATAFILE); if (NULL != hModule){ hResource = FindResource(hModule,"IDI_ICON3",RT_ICON); if (NULL != hResource) { IUXLogData("the resource exists\n",TRACE1); //LoadResource(hResource, ...); } else if ( NULL == hResource ) { sprintf(buff, "the %s app is not up to date with error %d\n", app, GetLastError()); IUXLogData(buff,IUX_ERROR); } FreeLibrary(hModule); } I'm still getting an 1814 error though. Still unsure why I am. Is the "IDI_ICON3" or the RT_ICON the wrong stuff? the ICON resource for my test is IDI_ICON3 and I'm sure its in the app I'm trying to open, so I'm confused as to why I'm seeing this. Any suggestions, insight, comments are greatly appreciated Thanks! Dan
-
Ok, I'm further in my understanding, but still no further in a solution. Here's what I have now: HMODULE hModule; HRSRC hResource; sprintf(buff,"%s.exe",app); hModule = LoadLibraryEx(buff,NULL,LOAD_LIBRARY_AS_DATAFILE); if (NULL != hModule){ hResource = FindResource(hModule,"IDI_ICON3",RT_ICON); if (NULL != hResource) { IUXLogData("the resource exists\n",TRACE1); //LoadResource(hResource, ...); } else if ( NULL == hResource ) { sprintf(buff, "the %s app is not up to date with error %d\n", app, GetLastError()); IUXLogData(buff,IUX_ERROR); } FreeLibrary(hModule); } I'm still getting an 1814 error though. Still unsure why I am. Is the "IDI_ICON3" or the RT_ICON the wrong stuff? the ICON resource for my test is IDI_ICON3 and I'm sure its in the app I'm trying to open, so I'm confused as to why I'm seeing this. Any suggestions, insight, comments are greatly appreciated Thanks! Dan
You need to wrap the IDI_ICON3 with MakeIntResource as shown in the snippet below: HRSRC hRscDLL = FindResource(NULL,MAKEINTRESOURCE(IDI_ICON3),RT_ICON); if (hRscDLL) { DWORD dwIconSize = SizeofResource(NULL,hRscDLL); HGLOBAL hMem = LoadResource(NULL,hRscDLL); if (hMem) { LPVOID pIconBytes = LockResource(hMem); if (pIconBytes) { .........
-
You need to wrap the IDI_ICON3 with MakeIntResource as shown in the snippet below: HRSRC hRscDLL = FindResource(NULL,MAKEINTRESOURCE(IDI_ICON3),RT_ICON); if (hRscDLL) { DWORD dwIconSize = SizeofResource(NULL,hRscDLL); HGLOBAL hMem = LoadResource(NULL,hRscDLL); if (hMem) { LPVOID pIconBytes = LockResource(hMem); if (pIconBytes) { .........
Still not having any luck :mad: Now i have this: hResource = FindResource(hModule,MAKEINTRESOURCE(IDI_ICON3),RT_ICON); but yet it still comes back as NULL :confused: Here is how it's defined in the .rc file for the app I'm loading: // Icon with lowest ID value placed first to ensure application icon // remains consistent on all systems. IDI_ICON3 ICON DISCARDABLE "Eye.ico" So what the heck am I doing wrong? Any other ideas, suggestions, comments? You're helping alot so far. thanks! Dan
-
Still not having any luck :mad: Now i have this: hResource = FindResource(hModule,MAKEINTRESOURCE(IDI_ICON3),RT_ICON); but yet it still comes back as NULL :confused: Here is how it's defined in the .rc file for the app I'm loading: // Icon with lowest ID value placed first to ensure application icon // remains consistent on all systems. IDI_ICON3 ICON DISCARDABLE "Eye.ico" So what the heck am I doing wrong? Any other ideas, suggestions, comments? You're helping alot so far. thanks! Dan
Does IDI_ICON3 equate to the same number in both applications?
-
Does IDI_ICON3 equate to the same number in both applications?
DavidCrow wrote: Does IDI_ICON3 equate to the same number in both applications? :laugh: good question. But yes they are the same number. I made sure they were. The number is 104, and I made sure that the number is the same. any other ideas :confused: Thanks! Dan
-
DavidCrow wrote: Does IDI_ICON3 equate to the same number in both applications? :laugh: good question. But yes they are the same number. I made sure they were. The number is 104, and I made sure that the number is the same. any other ideas :confused: Thanks! Dan
Woo Hoo! I finally understand it! Turns out that I need to be using the RT_GROUP_ICON because I'm not using hardware-dependent icons. :) I was then able to try other resource types and successfully got the information I needed. Thanks Guys! I really appreciate the help! Dan