Author Topic: Title bar icon not showing if GetModuleHandleEx is used  (Read 1049 times)

bluedevil

  • Member
  • **
  • Posts: 207
  • Binary Grinder
    • SCTZine
Title bar icon not showing if GetModuleHandleEx is used
« 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:
Code: [Select]

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:

Code: [Select]
    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
« Last Edit: September 26, 2022, 07:01:38 PM by bluedevil »
..Dreams make the future
But the past never lies..
BlueDeviL // SCT
My Code Site:
BlueDeviL Github

Vortex

  • Member
  • *****
  • Posts: 2790
Re: Title bar icon not showing if GetModuleHandleEx is used
« Reply #1 on: September 12, 2022, 05:52:12 AM »
Hello,

Code: [Select]
WinMainCRTStartup proc
   
    invoke  GetModuleHandleEx,0,0,hInstance

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

Greenhorn

  • Member
  • ***
  • Posts: 488
Re: Title bar icon not showing if GetModuleHandleEx is used
« Reply #2 on: September 12, 2022, 06:18:14 AM »
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

  • Member
  • **
  • Posts: 207
  • Binary Grinder
    • SCTZine
Re: Title bar icon not showing if GetModuleHandleEx is used
« Reply #3 on: September 12, 2022, 06:39:23 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:
Code: [Select]
    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

  • Member
  • *****
  • Posts: 13945
  • Assembly is fun ;-)
    • MasmBasic
Re: Title bar icon not showing if GetModuleHandleEx is used
« Reply #4 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.
« Last Edit: September 15, 2022, 05:13:34 PM by hutch-- »

bluedevil

  • Member
  • **
  • Posts: 207
  • Binary Grinder
    • SCTZine
Re: Title bar icon not showing if GetModuleHandleEx is used
« Reply #5 on: September 12, 2022, 06:56:25 PM »
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 =)
« Last Edit: September 15, 2022, 05:13:10 PM by hutch-- »
..Dreams make the future
But the past never lies..
BlueDeviL // SCT
My Code Site:
BlueDeviL Github