News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

hWnd member of WndProc changed...

Started by xandaz, January 04, 2022, 10:55:55 PM

Previous topic - Next topic

xandaz

    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...

HSE

Equations in Assembly: SmplMath

xandaz

    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.

xandaz

    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

xandaz

   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


HSE

Equations in Assembly: SmplMath

Greenhorn

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:
Kole Feut un Nordenwind gift en krusen Büdel un en lütten Pint.

xandaz

   Thanks. I appreciate the help. I didn't think it mattered the right size of the buffer.
   Edith said the same thing about me.

Greenhorn

I had to correct errors again. Post is updated.
Kole Feut un Nordenwind gift en krusen Büdel un en lütten Pint.

jj2007

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

TimoVJL

It depends of created windows in same classes.
Usually programmer creates only one frame window using registered windowclass with WndProc.
May the source be with you

hutch--

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.

NoCforMe

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.
Assembly language programming should be fun. That's why I do it.