The MASM Forum

General => The Campus => Topic started by: xandaz on November 01, 2020, 03:49:57 AM

Title: Rebar Window fails to create | invalid handle
Post by: xandaz on November 01, 2020, 03:49:57 AM
   hey guys. I was making a ReBar Controls but Olly gives invalid handle. Can Someone help.Thanks in advance,
.elseif uMsg==WM_CREATE
        mov     edi,lParam
        .if     [edi.CREATESTRUCT.hwndParent]==0
                invoke CreateWindowEx,0,addr ReBarClass,addr ReBarName\
                ,WS_VISIBLE+WS_CHILD+RBS_AUTOSIZE+RBS_VERTICALGRIPPER,\
                0,0,MainWindowWidth-10,40,hWnd,0,hInstance,0
                mov     hReBar,eax
       .endif 
Title: Re: Rebar Window fails to create | invalid handle
Post by: Biterider on November 01, 2020, 04:12:59 AM
Hi
Use GetLastError to get an indication of what is going wrong.
I suspect the class name is wrong. It should be "ReBarWindow32".

Regards, Biterider
Title: Re: Rebar Window fails to create | invalid handle
Post by: jj2007 on November 01, 2020, 04:33:28 AM
Quote from: xandaz on November 01, 2020, 03:49:57 AMOlly gives invalid handle

CreateWindowEx may return an error code, but it is valid only if eax==0. Have you checked that? Did you call InitCommonControls before creating the Rebar?

Title: Re: Rebar Window fails to create | invalid handle
Post by: xandaz on November 01, 2020, 04:35:09 AM
  it gives invalid_handle_value. ClassName is correct
Title: Re: Rebar Window fails to create | invalid handle
Post by: Biterider on November 01, 2020, 04:41:22 AM
Hi
"it gives invalid_handle_value."
The 9th parameter of CreateWindowEx should be the parent window. What is hWnd in your implementation?

Biterider
Title: Re: Rebar Window fails to create | invalid handle
Post by: xandaz on November 01, 2020, 04:48:22 AM
 it's hWnd from WndProc.
Title: Re: Rebar Window fails to create | invalid handle
Post by: xandaz on November 01, 2020, 04:56:49 AM
   Call to GetLastError gives the same ERROR_INVLID_HANDLE
Title: Re: Rebar Window fails to create | invalid handle
Post by: xandaz on November 01, 2020, 05:00:59 AM
    Sorry. Get last error gives 6 as error
Title: Re: Rebar Window fails to create | invalid handle
Post by: xandaz on November 01, 2020, 05:03:54 AM
   Is it possible it is a valid handle value?
Title: Re: Rebar Window fails to create | invalid handle
Post by: Biterider on November 01, 2020, 05:09:45 AM
Hi
That is OK, ERROR_INVLID_HANDLE = 6.
If the returned value from CreateWindowEx is zero, check the GetLastError value before and after the invocation. This is to make sure that the error value is set.
Check the hWnd value, maybe using it for another call (ShowWindow). Use the debugger to look into the parameters and verify the requirements listed here https://docs.microsoft.com/en-us/windows/win32/controls/create-rebar-controls (https://docs.microsoft.com/en-us/windows/win32/controls/create-rebar-controls)

Biterider
Title: Re: Rebar Window fails to create | invalid handle
Post by: xandaz on November 01, 2020, 05:15:58 AM
ty
Title: Re: Rebar Window fails to create | invalid handle
Post by: xandaz on November 01, 2020, 05:19:24 AM
   Works fine with another function... it's one of those things that are before my eyes and i can't see it. thanks a lot
Title: Re: Rebar Window fails to create | invalid handle
Post by: xandaz on November 01, 2020, 06:44:12 AM
    Shouldn't hWnd be valid for WM_CREATE message?
Title: Re: Rebar Window fails to create | invalid handle
Post by: xandaz on November 01, 2020, 07:17:08 AM
   Don't know what's happening. Tried to creater a Button and hWnd works fine.
Title: Re: Rebar Window fails to create | invalid handle
Post by: HSE on November 01, 2020, 07:25:29 AM
Hi!

Have you loaded ICC_COOL_CLASSES in InitCommonControlsEx?
Title: Re: Rebar Window fails to create | invalid handle
Post by: xandaz on November 01, 2020, 07:51:32 AM
here's the code
__UNICODE__     equ     1
.586
.model flat,stdcall
option casemap:none

WinMain PROTO   :DWORD,:DWORD,:DWORD,:DWORD
WndProc PROTO   :DWORD,:DWORD,:DWORD,:DWORD

include c:\masm32\include\windows.inc
include c:\masm32\include\user32.inc
include c:\masm32\include\kernel32.inc
include c:\masm32\include\comctl32.inc

includelib  c:\masm32\lib\user32.lib
includelib  c:\masm32\lib\kernel32.lib
includelib  c:\masm32\lib\comctl32.lib

include c:\masm32\macros\macros.asm
include ..\winclasses.asm

.const

MainWindowWidth     equ     700
MainWindowHeight    equ     500


.data
hInstance       HINSTANCE       ?
hMainWindow     HWND         ?
wcMain          WNDCLASSEX  <sizeof wcMain,CS_HREDRAW+CS_VREDRAW,offset WndProc,\
                0,0,?,?,?,COLOR_WINDOW,0,offset MainWindowClass,0>
UCSTR           MainWindowClass,"MainWindowClass",0
UCSTR           MainWindowName,"Window",0
iccx            INITCOMMONCONTROLSEX    <sizeof iccx,ICC_COOL_CLASSES+ICC_BAR_CLASSES>
UCSTR           ReBarClass,"ReBarWindow32",0
hReBar          HWND        ?
UCSTR           ReBarName,"ReBar",0
hToolbar        HWND        ?
TBButtons       TBBUTTON <0,100h,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0>
                TBBUTTON      <0,101h,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0>
                TBBUTTON      <0,102h,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0>


.code
    start: 
        invoke  GetModuleHandle,0
        mov     hInstance,eax
        invoke  InitCommonControlsEx,addr iccx
        invoke  WinMain,hInstance,0,0,SW_SHOWNORMAL
        invoke  ExitProcess,eax

WinMain PROC    hInst:DWORD,hPrevInst:DWORD,CmdLine:DWORD,CmdShow:DWORD

    local   msg:MSG

    invoke  LoadIcon,0,IDI_APPLICATION
    mov     wcMain.hIcon,eax
    mov     wcMain.hIconSm,eax
    invoke  LoadCursor,0,IDC_ARROW
    mov     wcMain.hCursor,eax
    push    hInst
    pop     wcMain.hInstance
    invoke  RegisterClassEx,addr wcMain
    invoke  GetSystemMetrics,SM_CYSCREEN
    shr     eax,1
    sub     eax,MainWindowHeight/2
    push    eax
    invoke  GetSystemMetrics,SM_CXSCREEN
    shr     eax,1
    sub     eax,MainWindowWidth/2
    pop     ebx
    invoke  CreateWindowEx,0,addr MainWindowClass,addr MainWindowName,\
                WS_OVERLAPPEDWINDOW,\
                eax,ebx,MainWindowWidth,MainWindowHeight,\
                0,0,hInst,0
    mov     hMainWindow,eax
    invoke  ShowWindow,eax,CmdShow
    invoke  UpdateWindow,hMainWindow

msg_loop:
    invoke  GetMessage,addr msg,NULL,0,0
    or      eax,eax
    jz      end_msg_loop
    invoke  TranslateMessage,addr msg
    invoke  DispatchMessage,addr msg
    jmp     msg_loop
end_msg_loop:
    mov     eax,msg.wParam
    ret

WinMain endp

WndProc     PROC    hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD

    .if     uMsg==WM_DESTROY
        invoke  PostQuitMessage,0
       
    .elseif uMsg==WM_CREATE
        mov     edi,lParam
        .if     [edi.CREATESTRUCT.hwndParent]==NULL

                invoke CreateWindowExW,WS_EX_TOOLWINDOW,addr ReBarClass,addr ReBarName,\
                    WS_VISIBLE+WS_CHILD+RBS_AUTOSIZE+RBS_VERTICALGRIPPER+CCS_NODIVIDER,\
                    0,0,200,40,hWnd,10h,hInstance,0
                mov     hReBar,eax
                invoke  CreateWindowEx,0,WC_TOOLBARWINDOW32,0,WS_VISIBLE+WS_CHILD+TBSTYLE_FLAT,\
                    0,0,MainWindowWidth,40,hReBar,0,hInstance,0
                mov     hToolbar,eax
                invoke  SendMessage,eax,TB_BUTTONSTRUCTSIZE,sizeof TBBUTTON,0
                invoke  SendMessage,hToolbar,TB_ADDBUTTONS,3,addr TBButtons
                invoke  SendMessage,hToolbar,TB_AUTOSIZE,0,0
       .endif                                               
    .else       
        invoke  DefWindowProc,hWnd,uMsg,wParam,lParam
        ret
    .endif
    xor eax,eax
    ret
           

WndProc     endp   

end start
Title: Re: Rebar Window fails to create | invalid handle
Post by: jj2007 on November 01, 2020, 08:14:54 AM
Can you post include ..\winclasses.asm?
Title: Re: Rebar Window fails to create | invalid handle
Post by: xandaz on November 01, 2020, 08:18:09 AM
.data
UCSTR   WC_BUTTON,"Button",0
UCSTR   WC_COMBOBOX,"ComboBox",0
UCSTR   WC_COMBOBOXEX32,"ComboBoxEx32",0
UCSTR   WC_COMBOLBOX,"ComboLBox",0
UCSTR   WC_COMMCTRL_DRAGLISTMSG,"commctrl_DragListMsg",0
UCSTR   WC_CONTROLBAR,"AfxControlBar",0
UCSTR   WC_DDEMLEVENT,"DDEMLEvent",0
UCSTR   WC_DESKTOP,"#32769",0
UCSTR   WC_DIALOGBOX,"#32770",0
UCSTR   WC_EDIT,"Edit",0
UCSTR   WC_HTML_INTERNET_EXPLORER,"HTML_Internet Explorer",0
UCSTR   WC_ICONTITLE,"#32772",0
UCSTR   WC_IE,"Internet Explorer_Server",0
UCSTR   WC_LISTBOX,"ListBox",0
UCSTR   WC_MDICLIENT,"MDIClient",0
UCSTR   WC_MENU,"#32768",0
UCSTR   WC_MESSAGE,"Message",0
UCSTR   WC_MFCDIALOGBAR,"MfcDialogBar",0
UCSTR   WC_MFCFRAME,"MfcFrame",0
UCSTR   WC_MFCMDICHILD,"MfcFrameMDIChild",0
UCSTR   WC_MFCMDIFRAME,"MfcFrameMDI",0
UCSTR   WC_MFCMINIDOCKFRAME,"MfcFrameMiniDock",0
UCSTR   WC_MFCMINIFRAME,"MfcFrameMini",0
UCSTR   WC_MFCSPLITTER,"MfcSplitter",0
UCSTR   WC_MFCVIEW,"MfcView",0
UCSTR   WC_MFCWND,"MfcWnd",0
UCSTR   WC_MSCTLS_HOTKEY32,"msctls_hotkey32",0
UCSTR   WC_MSCTLS_PROGRESS32,"msctls_progress32",0
UCSTR   WC_MSCTLS_STATUSBAR32,"msctls_statusbar32",0
UCSTR   WC_MSCTLS_TRACKBAR32,"msctls_trackbar32",0
UCSTR   WC_MSCTLS_UPDOWN16,"msctls_updown",0
UCSTR   WC_MSCTLS_UPDOWN32,"msctls_updown32",0
UCSTR   WC_MSTASKSWWCLASS, "MSTaskSwWClass"
UCSTR   WC_NATIVEFONTCTL,"NativeFontCtl",0
UCSTR   WC_OCHOST,"OCHost",0
UCSTR   WC_OPENLISTVIEW,"OpenListView",0
UCSTR   WC_REBARWINDOW32,"ReBarWindow32",0
UCSTR   WC_RICHEDIT,"Richedit",0
UCSTR   WC_RICHEDIT20,"RichEdit20W",0
UCSTR   WC_RICHEDIT20A,"RichEdit20a",0
UCSTR   WC_RICHEDIT50W,"RichEdit50W",0
UCSTR   WC_SCROLLBAR,"Scrollbar",0
UCSTR   WC_SHDOCOBJV,"Shell DocObject View",0
UCSTR   WC_SHELLDLLDEFVIEW,"SHELLDLL_DefView",0
UCSTR   WC_SHELLEMBEDDING,"Shell Embedding",0
UCSTR   WC_STATIC,"Static",0
UCSTR   WC_SWITCHWND,"#32771",0
UCSTR   WC_SYSANIMATE32,"SysAnimate32",0
UCSTR   WC_SYSDATETIMEPICK32,"SysDateTimePick32",0
UCSTR   WC_SYSHEADER32,"SysHeader32",0
UCSTR   WC_SYSIPADDRESS32,"SysIPAddress32",0
UCSTR   WC_SYSLINK,"SysLink",0
UCSTR   WC_SYSLISTVIEW32,"SysListView32",0
UCSTR   WC_SYSMONTHCAL32,"SysMonthCal32",0
UCSTR   WC_SYSPAGER,"SysPager",0
UCSTR   WC_SYSTABCONTROL32,"SysTabControl32",0
UCSTR   WC_SYSTREEVIEW32,"SysTreeView32",0
UCSTR   WC_THUMBNAILVIEW,"ThumbnailVwExtWnd32",0
UCSTR   WC_TOOLBARWINDOW32,"ToolbarWindow32",0
UCSTR   WC_TOOLTIPS_CLASS16,"tooltips_class",0
UCSTR   WC_TOOLTIPS_CLASS32,"tooltips_class32",0
UCSTR   WC_TRAYCLOCKWCLASS,"TrayClockWClass",0
UCSTR   WC_TRAYNOTIFYWND,"TrayNotifyWnd",0
Title: Re: Rebar Window fails to create | invalid handle
Post by: xandaz on November 01, 2020, 08:43:33 AM
   Like i said i tried to create a button instead of the rebar control and it worked.
Title: Re: Rebar Window fails to create | invalid handle
Post by: HSE on November 01, 2020, 09:08:37 AM
Rebar is in place, just empty.

Is posible that you don't see nothing until to insert a band?

Title: Re: Rebar Window fails to create | invalid handle
Post by: xandaz on November 01, 2020, 09:10:31 AM
maybe
Title: Re: Rebar Window fails to create | invalid handle
Post by: jj2007 on November 01, 2020, 09:55:15 AM
invoke  CreateWindowEx,0, addr WC_TOOLBARWINDOW32

It wouldn't hurt if you did some error checking.
Title: Re: Rebar Window fails to create | invalid handle
Post by: xandaz on November 01, 2020, 10:04:12 AM
   yeah....there was king no error. The band  had to be inserted. sorry for making you think
Title: Re: Rebar Window fails to create | invalid handle
Post by: hutch-- on November 01, 2020, 11:23:58 PM
Something basic, at a WM_CREATE you can only use the handle supplied in the WndProc, once the CreateWindowEx() has returned you can use its handle as the parent for other controls.