The MASM Forum

64 bit assembler => 64 bit assembler. Conceptual Issues => Topic started by: bluedevil on September 12, 2022, 05:37:13 AM

Title: Title bar icon not showing if GetModuleHandleEx is used
Post by: bluedevil on September 12, 2022, 05:37:13 AM
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
Title: Re: Title bar icon not showing if GetModuleHandleEx is used
Post by: Vortex on September 12, 2022, 05:52:12 AM
Hello,

WinMainCRTStartup proc
   
    invoke  GetModuleHandleEx,0,0,hInstance


How do you set the value of hInstance? I think here is the problem.
Title: Re: Title bar icon not showing if GetModuleHandleEx is used
Post by: 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
Title: Re: Title bar icon not showing if GetModuleHandleEx is used
Post by: bluedevil on September 12, 2022, 06:39:23 AM
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
Title: Re: Title bar icon not showing if GetModuleHandleEx is used
Post by: 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.

I removed the "Solved" as this forum is not a paid help desk. Our members help who they can.
Title: Re: Title bar icon not showing if GetModuleHandleEx is used
Post by: bluedevil on September 12, 2022, 06:56:25 PM
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 =)