CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2012
    Posts
    3

    GetDlgItemTextW/SetDlgItemTextW do not want working

    I write a simple demo dialog-based application. I use Windows 7 x64 and ml64 from DDK 7600.16385.0. Dialog box has button ID_READ, edit control ID_DIAM and static control GLAND_LAB. I want to get text from edit control and set text to static control. I wrote small C application with such dialog procedure:
    Code:
    long long int __stdcall DlgProc(HWND hWnd, unsigned int i1, unsigned long long int i2, long long int i3)
    {
    const wchar_t string1[BUF_SIZE];
    if (i1 == WM_COMMAND)
    	if (i2 == ID_READ)
    	{
    		GetDlgItemTextW(hWnd, ID_DIAM, (wchar_t *)&string1,BUF_SIZE);
    		SetDlgItemTextW(hWnd, GLAND_LAB, (wchar_t *)&string1);
    	}
    return 0;
    }
    and tested it - works well.
    Then I wrote such assembler code:
    Code:
    dlgproc proc
    	push rbx
    	sub rsp, BUF_SIZE*2+20h
    	mov String, rsp
    
    	xor rax, rax
    	mov hDlg, rcx
    	cmp rdx, WM_COMMAND
    	jne NoCommand
    	cmp r8, ID_READ
    	jne NoCommand
    
    	; Get text:
    	mov r9, BUF_SIZE
    	mov r8, qword ptr [String]
    	mov rdx, ID_DIAM
    	call qword ptr [__imp_GetDlgItemTextW] ; access violation here!!!
    
            ; Set text:		
    	mov rcx, hDlg
    	mov rdx, GLAND_LAB
    	mov r8, qword ptr [String]
    	call qword ptr [__imp_SetDlgItemTextW]
    	jmp NoCommand
    
            ; out code:
    NoCommand:
    	add rsp, BUF_SIZE*2+20h
    	pop rbx
    	ret
    dlgproc endp
    And this code causes access violation executing function SetDlgItemTextW. I used debugger WinDbg and checked values of registers rcx and r8 before executing functions GetDlgItemText and SetDlgItemText - they are the same. But first function executes without errors, and second do not want to work. I can not find valuable differences between disassembled C code and my code. Maybe I do not know something?

  2. #2
    Join Date
    Jul 2012
    Posts
    3

    Re: GetDlgItemTextW/SetDlgItemTextW do not want working

    I found my mistake. Analysing C disassembled code, I found, that I must replace code
    Code:
        sub rsp, BUF_SIZE*2+20h
        mov String, rsp
    by code
    Code:
        sub rsp, BUF_SIZE*2+20h
        mov String, rsp
        add String, 22h
    I do not know why I have to add some offset to address, but - nothing works without it. What can be cause of it?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured