News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Title bar icon not showing if GetModuleHandleEx is used

Started by bluedevil, September 12, 2022, 05:37:13 AM

Previous topic - Next topic

bluedevil

While fiddling with GetModulehandle and GetModulehandleEx functions, I have realized that I cannot get icon be showed on title bar if I use GetModuleHandleEx

I made a modal dialog app using a resource file and using DialogBoxParam function:


WinMainCRTStartup proc
   
    invoke GetModuleHandle,0
    mov hInstance, rax
    .if(rax == 0)
        invoke  ExitProcess,NULL
    .endif
   
    invoke  GetCommandLine
    mov     CommandLine,rax
   
    invoke  InitCommonControls
    mov     icc.dwSize, sizeof INITCOMMONCONTROLSEX
    mov     icc.dwICC, ICC_COOL_CLASSES or ICC_STANDARD_CLASSES or ICC_WIN95_CLASSES
    invoke  InitCommonControlsEx, addr icc
   
    invoke  WinMain,hInstance, NULL, CommandLine, SW_SHOWDEFAULT
    invoke  ExitProcess,eax
   
    ret

WinMainCRTStartup endp

WinMain proc hInst:HINSTANCE, hPrevInstance:HINSTANCE, lpCmdLine:LPSTR, nCmdShow:DWORD

    invoke DialogBoxParam,hInst, IDD_DLG1, 0, addr DlgProc, NULL
    invoke ExitProcess,NULL

WinMain endp

DlgProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

    .if uMsg==WM_INITDIALOG
        invoke LoadIcon,hInstance,10
        invoke SendMessage,hWnd,WM_SETICON,ICON_SMALL,rax
        ret TRUE
    .elseif uMsg==WM_COMMAND
        ; code of controls, buttons, checkboxes...
    .elseif uMsg==WM_CLOSE
        invoke EndDialog,hWnd,0
        ret
    .else
        mov     eax,FALSE
        ret
    .endif
    mov     eax,TRUE
    ret

DlgProc endp

end


In the code above I have used GetModuleHandle and I can see the icon on title bar. Bu if I change GetModuleHandle to GetModuleHandleEx I cannot get icon on title bar:


    invoke  GetModuleHandleEx,0,0,hInstance
    .if(rax {} 0)
        invoke  ExitProcess,NULL
    .endif


* I am using latest MASM64 SDK
* I have GetModulehandleEx 's flag parameters
* I have attached sources
..Dreams make the future
But the past never lies..
BlueDeviL // SCT
My Code Site:
BlueDeviL Github

Vortex

Hello,

WinMainCRTStartup proc
   
    invoke  GetModuleHandleEx,0,0,hInstance


How do you set the value of hInstance? I think here is the problem.

Greenhorn

Third parameter of GetModuleHandleEx is a pointer to a variable.

invoke  GetModuleHandleEx,0,0,addr hInstance
Kole Feut un Nordenwind gift en krusen Büdel un en lütten Pint.

bluedevil

Quote from: Greenhorn on September 12, 2022, 06:18:14 AM
Third parameter of GetModuleHandleEx is a pointer to a variable.

invoke  GetModuleHandleEx,0,0,addr hInstance

OMG how did i missed that, I think i need to sleep right now! Thank you Greenhorn!

BTW solution:

    invoke  GetModuleHandleEx, 0, 0, addr hInstance
    .if(rax == 0)
        invoke  ExitProcess,NULL
    .endif
..Dreams make the future
But the past never lies..
BlueDeviL // SCT
My Code Site:
BlueDeviL Github

jj2007

#4
Why do you use the ex version? It's for special cases only, like DLLs etc

mov wc.hInstance, rv(GetModuleHandle, 0) does the job.

I removed the "Solved" as this forum is not a paid help desk. Our members help who they can.

bluedevil

#5
Quote from: jj2007 on September 12, 2022, 07:43:35 AM
Why do you use the ex version? It's for special cases only, like DLLs etc

mov wc.hInstance, rv(GetModuleHandle, 0) does the job.

As i mentioned on the first thread i was just fiddling with them. Not a special purpose right at the moment jj =)
..Dreams make the future
But the past never lies..
BlueDeviL // SCT
My Code Site:
BlueDeviL Github