News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Cann't load icon via LoadImage

Started by Rockphorr, August 01, 2022, 06:57:12 AM

Previous topic - Next topic

Rockphorr

Hi, can anyone explain to me why it does not work ?
A code below is a part of wm_paint processing.


;---------------------------
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

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?
Assembly language programming should be fun. That's why I do it.

jj2007

GetLastError after call DrawIcon returns what?

NoCforMe

Here's my self-contained routine that shows the last error. Very handy.


;====================================================================
; 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
Assembly language programming should be fun. That's why I do it.

Rockphorr

Quote from: jj2007 on August 01, 2022, 09:51:17 AM
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

Without seeing complete code, I can't tell you what's wrong.

Greenhorn

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

Quote from: Greenhorn 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.

I add it. There is no effect.

See a full asm source below please.

Rockphorr

Quote from: jj2007 on August 01, 2022, 09:55:19 PM
Without seeing complete code, I can't tell you what's wrong.
Ok! Here it is. See attachment.

quarantined

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

ok I see.. 7F05 == OIC_WINLOGO

But LoadImage doesnt seem to know what that is

quarantined

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

Quote from: quarantined on August 02, 2022, 04:04:57 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

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:
;---------------------------
push IDI_APPLICATION
push hInstance
call LoadIcon
;---------------------------
push EAX
push 10 ; Y
push 1 ; X
push hdc
call DrawIcon
;---------------------------


Even better:
;---------------------------
invoke LoadIcon, hInstance, IDI_APPLICATION
;---------------------------
invoke DrawIcon, hdc, 1, 10, eax
;---------------------------


Efficient:
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

jj, IDI_APPLICATION works fine.

Its IDI_WINLOGO that does not work

My screenshot in zip