The MASM Forum

General => The Campus => Topic started by: xandaz on January 04, 2022, 10:55:55 PM

Title: hWnd member of WndProc changed...
Post by: xandaz on January 04, 2022, 10:55:55 PM
    Hi guys. Is there any particular situation where the hWnd member of WndProc changes or gets set to null? I'm trying GetWindowText,hWnd,addr Buffer, sizeof Buffer and it doesn't work...
Title: Re: hWnd member of WndProc changed...
Post by: HSE on January 05, 2022, 12:29:08 AM
What is a member of WndProc?
Title: Re: hWnd member of WndProc changed...
Post by: xandaz on January 05, 2022, 01:27:49 AM
    I meant the PROTOTYPE member: hWnd. I'm going mad with this shit. Application gets lost in the memory space and it's not stack misaligned.
Title: Re: hWnd member of WndProc changed...
Post by: xandaz on January 05, 2022, 01:29:33 AM
    My programming is full of mud. All disorganized. just take a look at this         .elseif ax==IDM_CLOSEPROJECT
            .if ProjectFlag==FALSE
                invoke  MessageBox,hMainWindow,addr szNoProjectOpened,addr szAttention,MB_OK
            .else
              invoke MessageBox,hMainWindow,addr szKeepChanges,addr szAttention,MB_YESNO
.if eax==IDYES
invoke SaveFiles
.endif
       mov ecx,noMdiChild
       or ecx,ecx
       jz    dont_build
       invoke CreateFile,addr szProjectBuffer,GENERIC_WRITE,\
FILE_SHARE_WRITE,0,CREATE_ALWAYS,\
FILE_ATTRIBUTE_NORMAL,0
       mov     hProject,eax
              invoke  BuildProjectFile,hMainWindow
invoke MessageBoxA,0,addr ProjectFileBuffer,0,MB_OK
              invoke  CountBytes2,addr ProjectFileBuffer
              invoke  WriteFile,hProject,addr ProjectFileBuffer,ecx,\
                                  addr noBytesWritten,0
              invoke CloseHandle,hProject
              mov     ecx,noMdiChild
              or     ecx,ecx
              jz        no_close
loop_32:
                push    ecx
                invoke  SendMessage,hMdi,WM_MDINEXT,0,TRUE
  invoke SendMessage,hMdi,WM_MDIGETACTIVE,0,0
  mov hCurrentWindow,eax
                invoke  GetWindowLong,eax,GWL_USERDATA
  mov edi,eax
  test [edi.MdiStruct].dwFlags,IDF_UNTITLED
  jz skip_32
  dec noUntitledChild
skip_32:
         invoke LocalFree,[edi.MdiStruct].lpTextBuffer
                invoke  SendMessage,hMdi,WM_MDIDESTROY,hCurrentWindow,0
                pop     ecx
  dec ecx
                dec     noMdiChild
  cmp ecx,0
  jne loop_32
no_close:
               .if ProjectFlag==TRUE
            invoke  SetWindowText,hMainWindow,addr MainWindowName
              invoke  ClearMemory,addr ProjectFileBuffer,sizeof ProjectFileBuffer
              invoke  ClearMemory,addr MdiStructs,sizeof MdiStruct*20
mov ProjectFlag,FALSE
jmp _end

              .endif
dont_build:       
            mov     ProjectFlag,FALSE
.endif
Title: Re: hWnd member of WndProc changed...
Post by: xandaz on January 05, 2022, 02:07:26 AM
   The problem seems to be somewhere is this procedure:SaveFiles PROC

local hWindow;DWORD
local UserData:DWORD

mov ecx,noMdiChild
loop_0:
push ecx
invoke SendMessage,hMdi,WM_MDINEXT,0,TRUE
invoke SendMessage,hMdi,WM_MDIGETACTIVE,0,0
mov hWindow,eax
invoke     GetWindowLong,eax,GWL_USERDATA
mov UserData,eax
test [UserData.MdiStruct].dwFlags,IDF_UNTITLED
jz skip_1
invoke GetCurrentDirectoryA,sizeof szInitialDir,addr szInitialDir
lea esi,szInitialDir
cld
loop_1:
lodsb
or al,al
jnz loop_1
dec esi
mov byte ptr [esi],'\'
inc esi
invoke GetWindowTextA,hWindow,esi,MAX_PATH
invoke CopyBufferA,addr szInitialDir,addr [UserData.MdiStruct].szFile
jmp create_file
skip_1:
invoke CopyBufferA,addr [UserData.MdiStruct].szFile,addr szInitialDir
create_file:
invoke MessageBoxA,0,addr szInitialDir,0,MB_OK
invoke CreateFileA,addr szInitialDir,GENERIC_WRITE,\
FILE_SHARE_WRITE,0,CREATE_ALWAYS,\
FILE_ATTRIBUTE_NORMAL,0
push eax
mov EditStream.dwCookie,eax
mov EditStream.pfnCallback,offset StreamOutProc
mov eax,UserData
invoke SendMessage,[eax.MdiStruct].hEdit,EM_STREAMOUT,SF_TEXT,addr EditStream
pop eax
invoke CloseHandle,eax
pop ecx
dec ecx
or ecx,ecx
jnz loop_0
ret
SaveFiles endp

Title: Re: hWnd member of WndProc changed...
Post by: HSE on January 05, 2022, 02:45:19 AM
Where you set the title?
Title: Re: hWnd member of WndProc changed...
Post by: Greenhorn on January 05, 2022, 03:22:10 AM
invoke   GetCurrentDirectoryA, sizeof szInitialDir, addr szInitialDir

Is the value of sizeof szInitialDir correct ?! I guess it should be MAXPATH ???
What's the return value of GetCurrentDirectoryA ?

You don't need the loop_1 to search the last char in szInitialDir, you can use the return value of GetCurrentDirectoryA.
Check always for errors.


invoke   GetCurrentDirectoryA,MAXPATH,addr szInitialDir
.if (eax && eax < MAXPATH - 2)
     lea  esi, szInitialDir
     mov  BYTE ptr [esi+eax], '\'
     inc  eax
     mov  BYTE ptr [esi+eax], 0
;;   invoke   GetWindowTextA,hWindow,addr [esi+eax],MAX_PATH  ;; This will lead to buffer overflow !!! Calculate the difference between EAX and MAXPATH !
     mov  edx, MAXPATH
     sub  edx, eax
     invoke   GetWindowTextA,hWindow,addr [esi+eax],edx
     .if (!eax)
          ;; Error handling ...
     .endif
.else
     ;; Error handling ...
.endif


I hope I got it right ...

Edith said I had to correct some parts ...  :wink2:
Edith said: Do it again. :biggrin:
Edith said it's still erroneous, but now ...  :biggrin: :biggrin:
Edith said I'm a hopeless case ...  :tongue: :tongue: :tongue:
Title: Re: hWnd member of WndProc changed...
Post by: xandaz on January 05, 2022, 03:56:08 AM
   Thanks. I appreciate the help. I didn't think it mattered the right size of the buffer.
   Edith said the same thing about me.
Title: Re: hWnd member of WndProc changed...
Post by: Greenhorn on January 05, 2022, 04:00:56 AM
I had to correct errors again. Post is updated.
Title: Re: hWnd member of WndProc changed...
Post by: jj2007 on January 05, 2022, 10:33:23 AM
Quote from: xandaz on January 04, 2022, 10:55:55 PMIs there any particular situation where the hWnd member of WndProc changes or gets set to null?

No. The OS calls WndProc, and always passes the handle in the same position:

WndProc proc hWnd, uMsg, wParam:WPARAM, lParam:LPARAM
Title: Re: hWnd member of WndProc changed...
Post by: TimoVJL on January 05, 2022, 08:30:28 PM
It depends of created windows in same classes.
Usually programmer creates only one frame window using registered windowclass with WndProc.
Title: Re: hWnd member of WndProc changed...
Post by: hutch-- on January 05, 2022, 11:13:27 PM
JJ is correct here, a WndProc() is what is normally called a "callback". You tell the OS the name (location) in the WNDCLASSEX structure and the OS sends messages processed in the message loop to the WndProc.
Title: Re: hWnd member of WndProc changed...
Post by: NoCforMe on January 06, 2022, 03:27:35 PM
Small detail, but you need to save and restore ESI in your SaveFiles() procedure. Either PUSH and POP it, or put USES ESI in the proc declaration.