0

I am trying to load an icon from an array without success.

I have an array that contains a icon (.ico) in raw and I want to load it. The problem is that the function CreateIconFromResourceEx returns NULL.

About the icon I saved a .ico file in an array.

This is my code:

 HICON icon = NULL;

icon = CreateIconFromResourceEx(tray->icon, (DWORD)tray->fsize, TRUE, 0x30000, 32, 32, LR_DEFAULTCOLOR | LR_DEFAULTSIZE);

if (nid.hIcon) {
    DestroyIcon(nid.hIcon);
}

nid.hIcon = icon;
Shell_NotifyIcon(NIM_MODIFY, &nid);

where tray is:

struct tray {
unsigned char *icon;
int fsize;
struct tray_menu *menu;};

What am I doing wrong?

GiGa
  • 43
  • 5
  • 1
    ["If the function fails, the return value is NULL. To get extended error information, call GetLastError."](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-createiconfromresourceex) – Christian.K Apr 29 '20 at 14:19
  • ah sorry i forgot to add this information.. GetLastError return me 0 – GiGa Apr 29 '20 at 14:30
  • Have a look at this: https://stackoverflow.com/questions/41379285/load-hicon-from-the-buffer-ico-file. It might not give you an immediate answer, but there may be valuable information anyway. – Jabberwocky Apr 29 '20 at 14:44
  • @GiGa you shouldn't edit your question with the answer, but post an answer to your own question instead – Jabberwocky Apr 29 '20 at 17:06
  • @Jabberwocky thanks.. i fixed it – GiGa Apr 29 '20 at 18:59

1 Answers1

1

Found the problem.. i need calculate the offset for the IMAGEDATA

offset = LookupIconIdFromDirectoryEx(tray->icon, TRUE, 32, 64, LR_DEFAULTCOLOR);

than

if (offset != 0) {
    icon = CreateIconFromResourceEx(tray->icon + offset, (DWORD)tray->fsize, TRUE, 0x30000, 32, 64, LR_DEFAULTCOLOR);
}
GiGa
  • 43
  • 5