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

Quote from: jj2007 on August 02, 2022, 04:22:02 AM
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.

jj2007 thank you for your help, but it is not a problem.  A problem is null handle that LoadImage rerurns.

jj2007

Quote from: quarantined 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

Indeed. But this line works perfectly:
invoke DrawIcon, hdc, 100, 100, rv(LoadImage, hInstance, IDI_APPLICATION, IMAGE_ICON, 0, 0, LR_SHARED)

jj2007

Quote from: Rockphorr on August 02, 2022, 04:35:55 AMjj2007 thank you for your help, but it is not a problem.  A problem is null handle that LoadImage rerurns.

Use this:
invoke DrawIcon, hdc, 100, 100, rv(LoadImage, hInstance, IDI_APPLICATION, IMAGE_ICON, 0, 0, LR_SHARED)

quarantined

Quote
Indeed. But this line works perfectly:
invoke DrawIcon, hdc, 100, 100, rv(LoadImage, hInstance, IDI_APPLICATION, IMAGE_ICON, 0, 0, LR_SHARED)

Yes of course it does. BUT IDI_APPLICATION does work, even with LoadImage. He is trying to display OIC_WINLOGO (with LoadImage) doesn't work. Also IDI_WINLOGO does not work with LoadIcon either.

The application in his zip should be displaying two images, but the second (OIC_WINLOGO or IDI_WINLOGO) returns the error and ultimately fails. That is the problem. NOT WITH IDI_APPLICATION which works with LoadImage as well as with LoadIcon. Hope you understand this better now.

Rockphorr

Quote from: jj2007 on August 02, 2022, 05:00:34 AM
Quote from: Rockphorr on August 02, 2022, 04:35:55 AMjj2007 thank you for your help, but it is not a problem.  A problem is null handle that LoadImage rerurns.

Use this:
invoke DrawIcon, hdc, 100, 100, rv(LoadImage, hInstance, IDI_APPLICATION, IMAGE_ICON, 0, 0, LR_SHARED)

paint.asm(119) : error A2136: too many arguments to INVOKE
paint.asm(119) : error A2006: undefined symbol : rv
paint.asm(119) : error A2114: INVOKE argument type mismatch : argument : 4

What .inc is need ?

Greenhorn

Quote from: Rockphorr on August 02, 2022, 03:06:25 AM
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.

Try this.

;---------------------------
mov EAX,LR_SHARED or LR_DEFAULTSIZE
push EAX ;fuLoad
mov EAX,0h ;y height - if set to zero LR_DEFAULTSIZE must be set in fuLoad
push EAX ;cyDesired
mov EAX,0h ;x width - if set to zero LR_DEFAULTSIZE must be set in fuLoad
push EAX ;cxDesired
mov EAX,IMAGE_ICON
push EAX ;uType
mov EAX,OIC_WINLOGO
push EAX ;lpszName
xor EAX,EAX ; must be zero if lpszName is a system resource
push EAX ;hinst
call LoadImage
;---------------------------


Kole Feut un Nordenwind gift en krusen Büdel un en lütten Pint.

Rockphorr

Quote from: Greenhorn on August 02, 2022, 05:51:02 AM
Quote from: Rockphorr on August 02, 2022, 03:06:25 AM
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.

Try this.

;---------------------------
mov EAX,LR_SHARED or LR_DEFAULTSIZE
push EAX ;fuLoad
mov EAX,0h ;y height - if set to zero LR_DEFAULTSIZE must be set in fuLoad
push EAX ;cyDesired
mov EAX,0h ;x width - if set to zero LR_DEFAULTSIZE must be set in fuLoad
push EAX ;cxDesired
mov EAX,IMAGE_ICON
push EAX ;uType
mov EAX,OIC_WINLOGO
push EAX ;lpszName
xor EAX,EAX ; must be zero if lpszName is a system resource
push EAX ;hinst
call LoadImage
;---------------------------


i've tried it. A result is 1st  icon only.

NoCforMe

Don't know if this will help, but you can try it:
Run the attached program which displays (or is supposed to, anyhow) all the stock system icons. See if the icon you want shows up. (Look at the attached JPG to see what shows up on my computer for comparison.)

Maybe that icon isn't available on your system for some reason?
Assembly language programming should be fun. That's why I do it.

fearless

You are setting hInstance to 0 - or more accurately you are setting the parameter that requires hInst to 0. Try passing hInst / hInstance instead
or use GetModuleHandle, NULL and pass that value to the hInst / hInstance parameter of the LoadImage

quarantined

Quote from: fearless on August 02, 2022, 07:20:04 AM
You are setting hInstance to 0 - or more accurately you are setting the parameter that requires hInst to 0. Try passing hInst / hInstance instead
or use GetModuleHandle, NULL and pass that value to the hInst / hInstance parameter of the LoadImage

hInstance must be zero if lpszName is a system resource

From Win32.hlp:

The LoadImage function loads an icon, cursor, or bitmap.

HANDLE LoadImage(

    HINSTANCE hinst, // handle of the instance that contains the image
    LPCTSTR lpszName, // name or identifier of image
    UINT uType, // type of image
    int cxDesired, // desired width
    int cyDesired, // desired height
    UINT fuLoad // load flags
   );

Parameters
hinst
Identifies an instance of the module that contains the image to be loaded. To load an OEM image, set this parameter to zero.

Greenhorn

Quote


IDI_WINLOGO
MAKEINTRESOURCE(32517)
Default application icon.
Windows 2000:  Windows logo icon.

So, IDI_WINLOGO = OIC_WINLOGO = 32517 should load the default application icon and it works for me.
Kole Feut un Nordenwind gift en krusen Büdel un en lütten Pint.

jj2007

Quote from: quarantined on August 02, 2022, 05:03:42 AMthe second (OIC_WINLOGO or IDI_WINLOGO) returns the error and ultimately fails. That is the problem. NOT WITH IDI_APPLICATION which works with LoadImage as well as with LoadIcon. Hope you understand this better now.

I perfectly understand this. But unless your OS is Windows 2000, IDI_WINLOGO won't work. Unless, of course... :tongue:

QuoteLoadIconA

IDI_APPLICATION
MAKEINTRESOURCE(32512)

   Default application icon.
...
IDI_WINLOGO
MAKEINTRESOURCE(32517)

   Default application icon.

Windows 2000:  Windows logo icon.

Greenhorn

Quote from: jj2007 on August 02, 2022, 08:30:09 AM
Quote from: quarantined on August 02, 2022, 05:03:42 AMthe second (OIC_WINLOGO or IDI_WINLOGO) returns the error and ultimately fails. That is the problem. NOT WITH IDI_APPLICATION which works with LoadImage as well as with LoadIcon. Hope you understand this better now.

I perfectly understand this. But unless your OS is Windows 2000, IDI_WINLOGO won't work.

QuoteLoadIconA

IDI_APPLICATION
MAKEINTRESOURCE(32512)

   Default application icon.
...
IDI_WINLOGO
MAKEINTRESOURCE(32517)

   Default application icon.

Windows 2000:  Windows logo icon.

It seems that it is bypassed to the default application icon. The resource ID of the icon in user32.dll is 100.

LoadImage with IDI_WINLOGO loads the default application icon.
Kole Feut un Nordenwind gift en krusen Büdel un en lütten Pint.

quarantined

Quote from: jj2007 on August 02, 2022, 08:30:09 AM
I perfectly understand this. But unless your OS is Windows 2000, IDI_WINLOGO won't work. Unless, of course... :tongue:

Aha! You've found the missing link. I knew their had to be a (sort of) reasonable explanation to this.  :toothy:
I guess I just learnt something today.

I forget, who here still uses Windows 2000 to test this?

jj2007

Quote from: quarantined on August 02, 2022, 08:43:47 AMAha! You've found the missing link. I knew their had to be a (sort of) reasonable explanation to this.  :toothy:

There is one, and it is fairly simple. The exe I posted above (paint.zip) works fine, it shows two icons, one loaded with IDI_APPLICATION, the other with IDI_WINLOGO:

invoke DrawIcon, hdc, 10, 1, rv(LoadImage, hInstance, IDI_APPLICATION, IMAGE_ICON, 0, 0, LR_SHARED)
invoke DrawIcon, hdc, 100, 100, rv(LoadImage, hInstance, IDI_WINLOGO, IMAGE_ICON, 0, 0, LR_SHARED)


So, why does it work? Simply because I loaded the respective resources:
#include "resource.h"
IDI_APPLICATION ICON "\\Masm32\\MasmBasic\\icons\\Smiley.ico"
IDI_WINLOGO ICON "\\Masm32\\MasmBasic\\icons\\Globe.ico"
01 RT_MANIFEST "\\Masm32\\MasmBasic\\Res\\XpManifest.xml"


OP posts a snippet. After a while, he understands that complete code is needed. But he does not provide the RC file, or the required icons. Besides, he is a member of the Bare Metal Heros Club, alias the push push call brigade, so that his code is almost unreadable. All that adds together, and the result is chaos and confusion.

push EAX
mov EAX,10;Y
push EAX
mov EAX,1;X
push EAX
push hdc
call DrawIcon


When will he realise that
mov eax, 1
push eax

is just an unnecessary "verbose" way of doing
push 1?

When will he realise that in MASM you simply use invoke DrawIcon, hdc, 1, 10, eax?