About resouce files

Started by
11 comments, last by cambalinho 7 years, 11 months ago

lets simplificate the code...

1 st sample:

on resource.rc:


songoku ico "C:\\Users\\Cambalinho\\Documents\\CodeBlocks\\classcontrols\\bin\\Release\\x-7.ico"

FindResource():


HRSRC rscFind=FindResource(GetModuleHandle(NULL), MAKEINTRESOURCE(songoku ), "ico");

i get the resource correctly.

2nd sample:

on resource.rc:


songoku ICON "C:\\Users\\Cambalinho\\Documents\\CodeBlocks\\classcontrols\\bin\\Release\\x-7.ico"

FindResource():


HRSRC rscFind=FindResource(GetModuleHandle(NULL), MAKEINTRESOURCE(songoku ),RT_ICON);

why i get NULL? what i'm doing wrong with FindeResource()?

error: 1814 - ERROR_RESOURCE_NAME_NOT_FOUND: The specified resource name cannot be found in the image file.

Advertisement

A type of ico in the RC file, and "ico" in FindResource call, should result in a custom resource type. "ico" is not an existing resource type (https://msdn.microsoft.com/en-us/library/ms648009(v=vs.85).aspx), which means it's being imported and compiled in as a regular blob in the resources. This is why it gets found when finding it, there's no special handling going on and you're matching the RC type when finding it.

ICON and RT_ICON will do it's own special handling, and I've found that icons can be pretty tricky when used as resources. Have you made sure that the icon is valid and supported (no odd sizes/laters/color depths/etc)? Open the icon in Visual Studio and make sure it loads/looks correct, and try actually saving it there as well. Make sure you save it explicitly (Save As and overwrite, or save to a new name), otherwise it might not think it needs to save.

but if i use RT_GROUP_ICON, i will get what i need. it's confused some RC const's...

but now i can update more my function:


string GetResourceType(DWORD ResourceID)
{
    HRSRC rscFind;
    rscFind=FindResource(GetModuleHandle(NULL),(LPCTSTR)  MAKEINTRESOURCE(ResourceID), "anicur");
    if(rscFind!=NULL)
        return "ANICUR";
    rscFind=FindResource(GetModuleHandle(NULL),(LPCTSTR)  MAKEINTRESOURCE(ResourceID), "aniico");
    if(rscFind!=NULL)
        return "ANIICO";
    rscFind=FindResource(GetModuleHandle(NULL), (LPCTSTR) MAKEINTRESOURCE(ResourceID), "bmp");
    if(rscFind!=NULL)
        return "BMP";
    rscFind=FindResource(GetModuleHandle(NULL), (LPCTSTR) MAKEINTRESOURCE(ResourceID), RT_BITMAP);
    if(rscFind!=NULL)
        return "BMP";
    rscFind=FindResource(GetModuleHandle(NULL),(LPCTSTR)  MAKEINTRESOURCE(ResourceID), "cur");
    if(rscFind!=NULL)
        return "CUR";

    rscFind=FindResource(GetModuleHandle(NULL), (LPCTSTR) MAKEINTRESOURCE(ResourceID), "ico");
    if(rscFind!=NULL)
        return "ICO";
    rscFind=FindResource(GetModuleHandle(NULL), (LPCTSTR) MAKEINTRESOURCE(ResourceID), RT_GROUP_ICON);
    if(rscFind!=NULL)
        return "ICO";
    rscFind=FindResource(GetModuleHandle(NULL), (LPCTSTR) MAKEINTRESOURCE(ResourceID), RT_ICON);
    if(rscFind!=NULL)
        return "ICO";

    rscFind=FindResource(GetModuleHandle(NULL), (LPCTSTR) MAKEINTRESOURCE(ResourceID), "gif");
    if(rscFind!=NULL)
        return "GIF";

    return "OTHER";
}

how these function works:

if FindResource() returns NULL, means that the resource ID or type are wrong. using these thot, i create these function. now it can be automatic.

thanks for all

This topic is closed to new replies.

Advertisement