Author Topic: hWnd member of WndProc changed...  (Read 1378 times)

xandaz

  • Member
  • ****
  • Posts: 529
  • I luv you babe
    • My asm examples
hWnd member of WndProc changed...
« 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...

HSE

  • Member
  • *****
  • Posts: 2502
  • AMD 7-32 / i3 10-64
Re: hWnd member of WndProc changed...
« Reply #1 on: January 05, 2022, 12:29:08 AM »
What is a member of WndProc?
Equations in Assembly: SmplMath

xandaz

  • Member
  • ****
  • Posts: 529
  • I luv you babe
    • My asm examples
Re: hWnd member of WndProc changed...
« Reply #2 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.

xandaz

  • Member
  • ****
  • Posts: 529
  • I luv you babe
    • My asm examples
Re: hWnd member of WndProc changed...
« Reply #3 on: January 05, 2022, 01:29:33 AM »
    My programming is full of mud. All disorganized. just take a look at this
Code: [Select]
         .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

  • Member
  • ****
  • Posts: 529
  • I luv you babe
    • My asm examples
Re: hWnd member of WndProc changed...
« Reply #4 on: January 05, 2022, 02:07:26 AM »
   The problem seems to be somewhere is this procedure:
Code: [Select]
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

  • Member
  • *****
  • Posts: 2502
  • AMD 7-32 / i3 10-64
Re: hWnd member of WndProc changed...
« Reply #5 on: January 05, 2022, 02:45:19 AM »
Where you set the title?
Equations in Assembly: SmplMath

Greenhorn

  • Member
  • ***
  • Posts: 493
Re: hWnd member of WndProc changed...
« Reply #6 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:
Kole Feut un Nordenwind gift en krusen Büdel un en lütten Pint.

xandaz

  • Member
  • ****
  • Posts: 529
  • I luv you babe
    • My asm examples
Re: hWnd member of WndProc changed...
« Reply #7 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.

Greenhorn

  • Member
  • ***
  • Posts: 493
Re: hWnd member of WndProc changed...
« Reply #8 on: January 05, 2022, 04:00:56 AM »
I had to correct errors again. Post is updated.
Kole Feut un Nordenwind gift en krusen Büdel un en lütten Pint.

jj2007

  • Member
  • *****
  • Posts: 13957
  • Assembly is fun ;-)
    • MasmBasic
Re: hWnd member of WndProc changed...
« Reply #9 on: January 05, 2022, 10:33:23 AM »
Is 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

  • Member
  • *****
  • Posts: 1320
Re: hWnd member of WndProc changed...
« Reply #10 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.
May the source be with you

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 10583
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: hWnd member of WndProc changed...
« Reply #11 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.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

NoCforMe

  • Member
  • *****
  • Posts: 1124
Re: hWnd member of WndProc changed...
« Reply #12 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.