The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: hfheatherfox07 on April 28, 2011, 03:58:05 AM

Title: Using '%S' to set word
Post by: hfheatherfox07 on April 28, 2011, 03:58:05 AM
Hi, I saw this used in an example here on the MASM Forum for displaying your computer serial...
So I started messing with the concept,
and I was wondering why does it only work to display the word you enter correctly if you use one line ... and not more???

Please enter a word or some random text into the edit box and you will see what I mean....



Title: Re: Using '%S' to set word
Post by: donkey on April 28, 2011, 07:06:42 AM
Well, I would suspect this to start with:

invoke SendMessage,szString,WM_GETTEXT,sizeof szString,addr szString

SendMessage requires a handle in the first parameter.
Title: Re: Using '%S' to set word
Post by: hfheatherfox07 on April 29, 2011, 02:25:53 AM
Thank you for your response.... I love your Avatar by the way , just love those offset eyes ...

I don't know what you mean by what you said ... but I will definitely try to change that line and use something else....

P.S

I noticed that you are a TASM kind of guy

I found this example that is written in tasm and I wanted to make it for MASM but with a rsrc.rc ...
Would it be possible?

Sorry I figured you for the TASM Guru

This was so interesting but it is beyond my capabilites to uderstand...
Title: Re: Using '%S' to set word
Post by: dedndave on April 29, 2011, 02:47:38 AM
what Edgar means is...
invoke SendMessage,WindowHandleGoesHere,WM_GETTEXT,sizeof szString,addr szString
you can enter the name of the function into google - the MSDN page is usually the first thing to come up
http://msdn.microsoft.com/en-us/library/ms644950%28v=vs.85%29.aspx
then, on the left, click around for more info   :U

in this case, it is also handy to look up the docs on the specific message
http://msdn.microsoft.com/en-us/library/ms632627%28v=vs.85%29.aspx

as for the other program, that is an old DOS 16-bit program   :P
Title: Re: Using '%S' to set word
Post by: hfheatherfox07 on April 29, 2011, 03:01:24 AM
I am going to try that...

I also seen an example  GetDlgItemInt was used

http://msdn.microsoft.com/en-us/library/ms645485(v=vs.85).aspx

I might try this as well ....

Title: Re: Using '%S' to set word
Post by: dedndave on April 29, 2011, 03:35:03 AM
i used this message to get text from the edit control
        mov word ptr LineBuf,sizeof LineBuf-1
        INVOKE  SendMessage,hEdit,EM_GETLINE,0,offset LineBuf

http://msdn.microsoft.com/en-us/library/bb761584%28v=vs.85%29.aspx
you have to place the length of the buffer in the first word of the buffer
which is a little unusual for win32   :wink
Title: Re: Using '%S' to set word
Post by: dedndave on April 29, 2011, 03:42:01 AM
the trick is to know when they hit the enter key   :bg
Title: Re: Using '%S' to set word
Post by: hfheatherfox07 on April 29, 2011, 09:56:01 PM
Quote from: dedndave on April 29, 2011, 03:35:03 AM
i used this message to get text from the edit control
        mov word ptr LineBuf,sizeof LineBuf-1
        INVOKE  SendMessage,hEdit,EM_GETLINE,0,offset LineBuf

http://msdn.microsoft.com/en-us/library/bb761584%28v=vs.85%29.aspx
you have to place the length of the buffer in the first word of the buffer
which is a little unusual for win32   :wink

I tried this and still got the same results in the 2nd and 3rd line?
Title: Re: Using '%S' to set word
Post by: hfheatherfox07 on April 30, 2011, 10:58:52 PM
Quote from: donkey on April 28, 2011, 07:06:42 AM
Well, I would suspect this to start with:

invoke SendMessage,szString,WM_GETTEXT,sizeof szString,addr szString

SendMessage requires a handle in the first parameter.

I tried this and adding a handle seams to crash the app when you press "get text" button ... what am I doing wrong?

I looked at this post on  Obtaining the handle of a console window and got further confused:
http://www.masm32.com/board/index.php?PHPSESSID=9382dac5dec0e8908a744043597e6309&topic=11042;prev_next=next

it is something simple that I am over looking but what?

I tried

.data?

buffer db 512 dup(?)
bufout LPSTR ? <- instead of finalszString

invoke GetDlgItemText, hwnd, hedit1, addr buffer, 512

I am even thinking of a sacrificial edit box to copy the text there first?

Now that I started this it will bug me until a solution is found  :(
Title: Re: Using '%S' to set word
Post by: dedndave on April 30, 2011, 11:22:10 PM
when you create a window or control the handle is returned in EAX
if the control is created in resource, you may use GetDlgItem to get the handle
that function works for all windows or controls - it does not have to be a dialog or dialog item
the only handle i have found that i was unable to get so far is the caps lock tooltip handle in ES_PASSWORD controls - lol
Title: Re: Using '%S' to set word
Post by: hfheatherfox07 on April 30, 2011, 11:54:37 PM
can you get  that working ?? I am beat duno what else to do ... it does not make any sense that the word "%s" is only replaced once and not multiple times why??
Title: Re: Using '%S' to set word
Post by: Gunner on May 01, 2011, 12:27:48 AM
I was bored...  I didn't use wsprintf, I used szRep from the Masm32 lib... should get you started...
Title: Re: Using '%S' to set word
Post by: hfheatherfox07 on May 01, 2011, 12:30:37 AM
Thank you so much  :U
Title: Re: Using '%S' to set word
Post by: Gunner on May 01, 2011, 12:43:46 AM
To answer your question as to why wsprintf only replaced 1 %s.. you have 3 format types you want wsprintf to replace, so you have to give it 3 strings to replace with....

invoke  wsprintf,addr FinalszString,addr szString,addr buffer, addr buffer, addr  buffer  works... I just prefer szRep from the MASM lib  :bg
Title: Re: Using '%S' to set word
Post by: hfheatherfox07 on May 01, 2011, 12:52:28 AM
Thanks I am going through yours to try and fix mine so I can understand it ( not just copy it)


You commented this
COMMENT #
These should be in .data because they are initialized
buffer2 db 100 dup(0)
buffer   db 100 dup(0);this buffer is used to "hold" what we enter in the text box!
FinalszString   db 100 dup(0); buffer2 holds buffer + szString #

That would explain why I kept getting warnings at those address's I thought it was :

buffer2 db 100 dup(0)  instead of buffer2 db 100 dup(?)

I never realized that I needed to initialize them
I thought that because we do not know the  buffer size but know a max of 100 bytes ...they go into .data?

This might help me with some other examples that I am working on
I thought  that data that is defined "fixed" goes to .data
and data that is unknown but defined goes to .data?

Thank you so much again :bg
Title: Re: Using '%S' to set word
Post by: Gunner on May 01, 2011, 12:58:29 AM
No, you don't have to initialize your buffers, but you did with (0) so they have to go in the .data section for the string buffers to be in the .data? section you have to use (?) which means uninitialized.


buffer2 db 100 dup(0)

in the .data section will take up 100 bytes in your exe... where as

buffer2 db 100 dup(?) in the .data? section does not