i've posted something similair to this before, but ive been reviewing the code that was sent to me and trying to incoporate it into my program and it works, but not as simple as i want it to. what im looking for is to be able to set something like this

KeyCode db "hello",0


and then in the program, on clicckage of the button.. i want it to compare the user input of IDC_KEY and the KeyCode.
ive tried alot of stuff but i clearly dont have the experience to complete what im looking for and was wondering if someone would shed some light. thanks
Posted on 2003-10-24 23:14:34 by sTonER_DeVIOUS
The easiest method is to use lstrcmp or you can code your own for example



mov ecx, offset correct
mov edx, offset userinput
@@:
mov al, [ecx]
cmp al, [edx]
jnz @F
inc ecx
inc edx
or al,al
jnz @B

Or something like that.
Posted on 2003-10-25 00:21:27 by roticv
lstrcmp is exactly what im looking for thanks :)

invoke lstrcmp,hKey,TheKey


that is my code, but i need to know how i would set it so if they dont equal
then MessageBox Failed and if they are equal then MessageBox Correct

ive been messing with


.if eax!=0
invoke MessageBox Passed
.else
invoke MessageBox Failed
.endif


but that aint working so i need some help, thank you :)
Posted on 2003-10-25 15:15:40 by sTonER_DeVIOUS
You could also do the comparison directly with the following instructions.
mov esi, offset KeyCode

mov edi, offset IDC_KEY_input_buffer
mov ecx,6 ;number of letters in "hello" + terminating "0"
repz cmpsb ;repeat the comparison while the same
jz both_the_same
jnz not_the_same
Raymond
Posted on 2003-10-25 18:39:26 by Raymond
Originally posted by sTonER_DeVIOUS
lstrcmp is exactly what im looking for thanks :)

invoke lstrcmp,hKey,TheKey


that is my code, but i need to know how i would set it so if they dont equal
then MessageBox Failed and if they are equal then MessageBox Correct

ive been messing with


.if eax!=0
invoke MessageBox Passed
.else
invoke MessageBox Failed
.endif


but that aint working so i need some help, thank you :)

Not reading msdn? Take a look at the return value
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.


so instead it should be the other way wrong:


invoke lstrcmp, offset string1, offset string2
or eax, eax
jz correct_messagebox
wrong_messagebox:
...
correct_messagebox:
...
Posted on 2003-10-25 23:51:02 by roticv
roticv,

ive tried


invoke lstrcmp,offset hKey,offset TheKey
or eax, eax
jz correct_msgbx

correct_msgbx:
invoke MessageBox, CORRECT

wrong_msgbx:
invoke messageBox, WRONG


and i do that, and i click the compare button and both the message boxes are displayed... im not sure i fully understand the use of JZ... couldnt i just put..



jne wrong_msgbox

or

je correct_msgbx


thanks for your help
Posted on 2003-10-26 11:36:14 by sTonER_DeVIOUS
:tongue: You have put the CORRECT and WRONG part in the wrong order :tongue: .
Posted on 2003-10-26 13:49:56 by gliptic


invoke lstrcmp,offset TheKey,offset hKey
or eax, eax
jne wrong_messagebox


correct_messagebox:
invoke MessageBox,hWin,ADDR Accepted,ADDR AppTitle,MB_OK

wrong_messagebox:
invoke MessageBox,hWin,ADDR Denied,ADDR AppTitle,MB_OK


alright i have changed them so they are in the right order now.
so now everytime i type something wrong into the edit control
the wrong_messagebox appears. what would be the code so
the correct_messagebox would appear
i have tried


invoke lstrcmp,offset TheKey,offset hKey
or eax, eax
jne wrong_messagebox
je correct_messagebox

but ofcourse that doesnt work... so wondering if anyone could help me?
Posted on 2003-10-26 16:58:05 by sTonER_DeVIOUS
jz = je
jnz = jne

Same opcode just different name.

Have you tried my code or at least read up on what I have posted?
Posted on 2003-10-26 20:36:26 by roticv
yeah ive tried your code over and over again :P im gonna try this jz and jze or whatever real quick and ill tell ya how it goes
thanks
Posted on 2003-10-26 20:38:24 by sTonER_DeVIOUS
hmmmm



invoke lstrcmp,offset TheKey,offset hKey
or eax, eax
je correct_messagebox
jne wrong_messagebox


correct_messagebox:
invoke MessageBox,hWin,ADDR Accepted,ADDR AppTitle,MB_OK

wrong_messagebox:
invoke MessageBox,hWin,ADDR Denied,ADDR AppTitle,MB_OK


thats what i have, changed and everything and its still not working :P i dont know what to do
thank you for all the help you've given me so far btw
Posted on 2003-10-26 20:41:07 by sTonER_DeVIOUS
It is not the same as what I have posted....


invoke lstrcmp,offset TheKey,offset hKey
or eax, eax
jne correct_messagebox
wrong_messagebox:
invoke MessageBox,hWin,ADDR Denied,ADDR AppTitle,MB_OK
...
correct_messagebox:
invoke MessageBox,hWin,ADDR Accepted,ADDR AppTitle,MB_OK
...


or


invoke lstrcmp,offset TheKey,offset hKey
or eax, eax
jz wrong_messagebox
correct_messagebox:
invoke MessageBox,hWin,ADDR Accepted,ADDR AppTitle,MB_OK
...
wrong_messagebox:
invoke MessageBox,hWin,ADDR Denied,ADDR AppTitle,MB_OK
...



Anyway I just prefer jz to je and jnz to jne
Posted on 2003-10-26 20:44:11 by roticv
bah ive just confused myself... anyways
what i need is to check if what the user enters is equal the the hardcoded key
if it is, then display the correct messagebox
if it is not then display the wrong msgbox

its not really doing either of those as it is right now, just displaying whichever one is there
anything else i could do?

(edited cuz i confused myself while re-reading everything)
Posted on 2003-10-26 20:47:45 by sTonER_DeVIOUS
hope this is what you are searching for (had this ready see attachment for all the files that is needed)

.386
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib

DialogProc PROTO :DWORD,:DWORD,:DWORD,:DWORD

.const
DIALOG_1 equ 1
IDC_PUSHBUTTON1 equ 101
IDC_EDIT1 equ 103

.data

keyword db "HELLO",0
ritekeyword db "yep ur keyword is right",0
wrongkeyword db "nope ur keyword is wrong",0
caption db "my dumb keyword app",0

.data?

hInstance dd ?
Buffer1 db 20 dup (?)

.code

start:

main :
invoke GetModuleHandleA,NULL
mov hInstance ,eax
invoke DialogBoxParamA,hInstance,1,NULL,ADDR DialogProc,NULL
invoke ExitProcess,eax

DialogProc Proc handle:dword,message:dword,wParam:dword,lParam:dword

.if(message==WM_COMMAND)

mov eax,wParam
cmp ax,IDC_PUSHBUTTON1
jnz FINALE
invoke GetDlgItemTextA,handle,IDC_EDIT1,ADDR Buffer1,10h
cmp eax,0
jnz yepsomethinginedit

.elseif(message==WM_CLOSE)

invoke EndDialog,handle,NULL


.endif

FINALE:
xor eax,eax
ret




yepsomethinginedit:

mov esi,OFFSET Buffer1
mov edi,OFFSET keyword
mov ecx,6h
repe cmpsb
jnz notcorrect
invoke MessageBoxA,NULL,OFFSET ritekeyword,OFFSET caption,NULL
jmp FINALE

notcorrect:
invoke MessageBoxA,NULL,OFFSET wrongkeyword,OFFSET caption,NULL
jmp FINALE



DialogProc endp



end main
Posted on 2003-10-27 04:21:11 by bluffer
not useless.. it will serve its purpose, thank you for the help
i really appriciate it
Posted on 2003-10-27 08:26:23 by sTonER_DeVIOUS