News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Masm32 password input dialog window

Started by Bugaga, April 02, 2020, 08:05:30 PM

Previous topic - Next topic

Bugaga

Quote from: hutch-- on April 04, 2020, 12:14:10 PM
As learning dialogs from scratch is hard going, here is a working example of a proper resource dialog that does the basic interface stuff that you need. The main app is a resource dialog and it calls another resource dialog where you enter text. The text is then available to the caller and from there you can do whatever you need to do in terms of encryption and saving the data to disk.

Learning how to make dialogs is a bit complicated at first but once you are familiar with the techniques and code, they are reasonably straight forward after that.

I can't be thankful enough for your help and also others in this thread! Maybe it's me, but it was so hard to find any info about creating dialogs on Internet. :thumbsup:

Bugaga

Quote from: hutch-- on April 04, 2020, 12:14:10 PM
As learning dialogs from scratch is hard going, here is a working example of a proper resource dialog that does the basic interface stuff that you need.
I am sorry for more questions, in this example you attached, how the input is stored to pTxt variable? I see it is a DWORD, but it does not match with other DWORD strings I create. Tried using a debugger to see how the input is stored in pTxt, but no luck.
Here is the code:

; --------------------
  ; GLOBAL scope handles
  ; --------------------
    .data
      key dd 'pass', 0

And later:

    LOCAL pTxt  :DWORD
    LOCAL buffer[260]:BYTE

And later:

            lea eax, buffer                                         ; load buffer address
            mov pTxt, eax                                           ; cast it to a pointer
            invoke DialogBoxParam,hInstance,200,0,ADDR TxtProc,pTxt ; pass pointer to text dialog
          ; ----------------------------------------------------
          ; result if not cancelled is in buffer at pTxt address
          ; ----------------------------------------------------
            invoke lstrcmp, addr pTxt , addr key
            .if eax == 0
              fn MessageBox,hWin,pTxt,"Result",MB_OK
            .else
              fn MessageBox,hWin,"Wrong password!","Result",MB_OK
            .endif

hutch--

pTxt is a pointer to a buffer, the example did it as a local to simplify the use of memory rather than having to dynamically allocate memory. That pointer is passed through the last argument,

invoke DialogBoxParam,hInstance,200,0,ADDR TxtProc,pTxt

to the second dialog procedure. In the second procedure the pointer is received by the "lParam" argument and copied to the decorated global variable.

        .data?
          pbuf@@@@ dd ?                                             ; decorate to prevent accidental duplicates
        .code

This is so the pointer is not lost when another message is processed by the 2nd dialog proc.

The code,

invoke GetWindowText,dlgEd,pbuf@@@@,260

gets the text from the edit box if it exists and passes it back via the code,

invoke EndDialog,hWin,pbuf@@@@

What you have back at the caller is the local memory filled with whatever has been typed into the edit box. It is tested for an empty string and if not a zero, the data is then stored in the buffer that "pTxt" points to.

Now for the comparison you want to do with your password, you then use a string compare algo to test if they are the same or not. To use the API function "lstrcmp" you need to ensure that you are comparing the same thing, the address of each string, the pTxt from the dialog AND the stored password that you want to compare it with. Also look up the return values for "lstrcmp" as they are the type used in sort algos.

Return Values

If the function succeeds and the string pointed to by lpString1 is less than the string pointed to by lpString2, the return value is negative; if the string pointed to by lpString1 is greater than the string pointed to by lpString2, it is positive. If the strings are equal, the return value is zero.