Author Topic: Cann't load icon via LoadImage  (Read 4734 times)

Rockphorr

  • Member
  • **
  • Posts: 73
Cann't load icon via LoadImage
« on: August 01, 2022, 06:57:12 AM »
Hi, can anyone explain to me why it does not work ?
A code below is a part of wm_paint processing.

Code: [Select]
;---------------------------
mov EAX,IDI_APPLICATION
push EAX
xor EAX,EAX
push EAX
call LoadIcon
;---------------------------
push EAX
mov EAX,10;Y
push EAX
mov EAX,1;X
push EAX
push [EBP+@HDC]
call DrawIcon ; <--- here works fine !!!
;---------------------------
mov EAX,0
push EAX ;fuLoad
mov EAX,10h ;y height
push EAX ;cyDesired
mov EAX,10h ;x width
push EAX ;cxDesired
mov EAX,IMAGE_ICON
push EAX ;uType
mov EAX,OIC_WINLOGO
push EAX ;lpszName
xor EAX,EAX
push EAX ;hinst
call LoadImage  ; <------ here returns NULL --- WHY ?
;---------------------------
push EAX
mov EAX,200;Y
push EAX
mov EAX,1;X
push EAX
push [EBP+@HDC]
call DrawIcon ; <---- then here is nothing too

NoCforMe

  • Member
  • *****
  • Posts: 1124
Re: Cann't load icon via LoadImage
« Reply #1 on: August 01, 2022, 08:35:47 AM »
The only things that jump out at me on first looking at this are you assigning values to the cxDesired and cyDesired parameters. According to MSDN:

Quote
cxDesired [in]
The width, in pixels, of the icon or cursor. If this parameter is zero and the fuLoad parameter is LR_DEFAULTSIZE, the function uses the SM_CXICON or SM_CXCURSOR system metric value to set the width. If this parameter is zero and LR_DEFAULTSIZE is not used, the function uses the actual resource width.

Since you're setting the fuLoad parameter to zero, have you tried using zero for these?

jj2007

  • Member
  • *****
  • Posts: 13957
  • Assembly is fun ;-)
    • MasmBasic
Re: Cann't load icon via LoadImage
« Reply #2 on: August 01, 2022, 09:51:17 AM »
GetLastError after call DrawIcon returns what?

NoCforMe

  • Member
  • *****
  • Posts: 1124
Re: Cann't load icon via LoadImage
« Reply #3 on: August 01, 2022, 12:07:01 PM »
Here's my self-contained routine that shows the last error. Very handy.

Code: [Select]
;====================================================================
; Displays last Windows system error (assuming there was one), using
; GetLastError(). Formats message and displays it using MessageBox().
;
; Returns last error code.
;====================================================================

ShowLastError PROC
LOCAL buffer[256]:BYTE

CALL GetLastError
MOV EDX, EAX
PUSH EAX
INVOKE FormatMessage, FORMAT_MESSAGE_FROM_SYSTEM or FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, EDX, 0, ADDR buffer, SIZEOF buffer, NULL
INVOKE MessageBox, 0, ADDR buffer, NULL, MB_OK
POP EAX
RET

ShowLastError ENDP

Rockphorr

  • Member
  • **
  • Posts: 73
Re: Cann't load icon via LoadImage
« Reply #4 on: August 01, 2022, 08:46:46 PM »
GetLastError after call DrawIcon returns what?

I add call GetLastError after call LoadImage it returns 0 and after  call DrawIcon it returns 0 too. I watch it in ollydbg.

jj2007

  • Member
  • *****
  • Posts: 13957
  • Assembly is fun ;-)
    • MasmBasic
Re: Cann't load icon via LoadImage
« Reply #5 on: August 01, 2022, 09:55:19 PM »
Without seeing complete code, I can't tell you what's wrong.

Greenhorn

  • Member
  • ***
  • Posts: 493
Re: Cann't load icon via LoadImage
« Reply #6 on: August 01, 2022, 09:58:05 PM »
Hi Rockphorr,

you have to use LR_SHARED (0x00008000) for the fuLoad parameter since you try to load a system icon.
Kole Feut un Nordenwind gift en krusen Büdel un en lütten Pint.

Rockphorr

  • Member
  • **
  • Posts: 73
Re: Cann't load icon via LoadImage
« Reply #7 on: August 02, 2022, 03:06:25 AM »
Hi Rockphorr,

you have to use LR_SHARED (0x00008000) for the fuLoad parameter since you try to load a system icon.

I add it. There is no effect.

See a full asm source below please.

Rockphorr

  • Member
  • **
  • Posts: 73
Re: Cann't load icon via LoadImage
« Reply #8 on: August 02, 2022, 03:08:03 AM »
Without seeing complete code, I can't tell you what's wrong.
Ok! Here it is. See attachment.

quarantined

  • Guest
Re: Cann't load icon via LoadImage
« Reply #9 on: August 02, 2022, 03:49:11 AM »
mov eax, 7F05  ; <--- resource ID??? but no resource file


That is what I see...
Should be 2 icons in the window, correct?

Shows standard application icon and nothing further. Upon calling LoadImage for the second icon, "ERROR_RESOURCE_DATA_NOT_FOUND" reported by olly

quarantined

  • Guest
Re: Cann't load icon via LoadImage
« Reply #10 on: August 02, 2022, 03:54:13 AM »
ok I see.. 7F05 == OIC_WINLOGO

But LoadImage doesnt seem to know what that is

quarantined

  • Guest
Re: Cann't load icon via LoadImage
« Reply #11 on: August 02, 2022, 04:04:57 AM »
I then tried:

      mov   EAX, IDI_WINLOGO  ;; which apparently is the same as OIC_WINLOGO
      push   EAX   ;lpszName
      mov   EAX, hInstance
      push   EAX   ;hinst
 
      call LoadIcon


with the same result...
Windows 7 32 bit here btw


I would be tempted then to extract the wanted icon to file and create a resource file for it and do it that way. Unless there is something we are both not seeing

Rockphorr

  • Member
  • **
  • Posts: 73
Re: Cann't load icon via LoadImage
« Reply #12 on: August 02, 2022, 04:15:14 AM »

mov eax, 7F05  ; <--- resource ID??? but no resource file


That is what I see...
Should be 2 icons in the window, correct?

Shows standard application icon and nothing further. Upon calling LoadImage for the second icon, "ERROR_RESOURCE_DATA_NOT_FOUND" reported by olly


ok I see.. 7F05 == OIC_WINLOGO

But LoadImage doesnt seem to know what that is

I then tried:

      mov   EAX, IDI_WINLOGO
      push   EAX   ;lpszName
      mov   EAX, hInstance
      push   EAX   ;hinst
 
      call LoadIcon


with the same result...
Windows 7 32 bit here btw


I would be tempted then to extract the wanted icon to file and create a resource file for it and do it that way. Unless there is something we are both not seeing

Yes, should be 2 icons in the window.

 IDI_WINLOGO and OIC_WINLOGO are just the same value.
 I use win95osr2 and ollydbg110,  I cann't see "ERROR_RESOURCE_DATA_NOT_FOUND", my screenshot is in attachment.


jj2007

  • Member
  • *****
  • Posts: 13957
  • Assembly is fun ;-)
    • MasmBasic
Re: Cann't load icon via LoadImage
« Reply #13 on: August 02, 2022, 04:22:02 AM »
Code: [Select]
mov EAX,IDI_APPLICATION
push EAX
; xor EAX,EAX
push hInstance  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
call LoadIcon
;---------------------------
push EAX
mov EAX,10;Y
push EAX
mov EAX,1;X
push EAX
push hdc
call DrawIcon

Better:
Code: [Select]
;---------------------------
push IDI_APPLICATION
push hInstance
call LoadIcon
;---------------------------
push EAX
push 10 ; Y
push 1 ; X
push hdc
call DrawIcon
;---------------------------

Even better:
Code: [Select]
;---------------------------
invoke LoadIcon, hInstance, IDI_APPLICATION
;---------------------------
invoke DrawIcon, hdc, 1, 10, eax
;---------------------------

Efficient:
Code: [Select]
invoke DrawIcon, hdc, 1, 10, rv(LoadIcon, hInstance, IDI_APPLICATION)
And, of course, IDI_APPLICATION is useless if there is no IDI_APPLICATION icon resource.

quarantined

  • Guest
Re: Cann't load icon via LoadImage
« Reply #14 on: August 02, 2022, 04:27:51 AM »
jj, IDI_APPLICATION works fine.

Its IDI_WINLOGO that does not work

My screenshot in zip