I'm very frustrated. Every time when I think I become better in asm I don't get the easiest stuff running. :(

I only want to show the Mouse-Pos in an Edit-Box.
I create an event:


I looked at the Win32-Help and found out that lParam contains the x-y-Position.
For the first time I only wanted the X-Pos, Which is in ax after that:
mov eax,lParam

Isn't it?

Then I thought I get it in the Msg-Box with:
invoke SetWindowText,hEdit,?

What to Insert for ?

I gave ax to a var:
xPos dw ?

mov eax,lParam
mov xPos,ax

But when I replace ? with xPos I only get strange chars like:
? or N when I klick the Mouse.
What's wrong now? :(
Posted on 2002-07-26 16:59:05 by Subby
did you read the API declaration?

BOOL SetWindowText(HWND hwnd, LPCTSTR lpsz)

seems pretty clear to me. :)
Posted on 2002-07-26 17:20:34 by Hiroshimator
Yeah, probably it does, but as I said I'm a newbee.
For example I don't know how to 0-Terminate it.
Posted on 2002-07-26 17:27:38 by Subby
but do you understand the nature of your error? :)
Posted on 2002-07-26 17:30:31 by Hiroshimator
Subby, you're on the right track but you're missing a crucial step.

As Hiroshimator pointed out, the proc is looking for a LPCTSTR value.

That is, a long pointer to a (null-terminated) string.

You are passing a dword number to the SetWindowText API. The procedure, in turn, treats the xPos value as a pointer to a string and will read from some random place in memory.

There are 2 things you have to change:

1) instead of just moving the eax to xPos you have to convert it to a null terminated string. If you are using MASM32, look through the MASM32 LIB Help for a procedure called dwtoa.

2) instead of passing xPos, pass ADDR xPos to SetWindowText. This'll pass the long pointer to the var instead. Also, you'll want to change your definition of xPos, since a dword probably won't hold the null terminated string. Allocate 6 bytes for a word value.

Posted on 2002-07-26 17:48:28 by chorus
The problem is that you get the values in Hex and you want them to be displayed in Ascii ;)

Masmlib has some functions like dwtoa (dwordToAscii) which will help you display those values. Check out the masmlib.hlp file in your masm32 folder.

Also wsprintf could be used, which I like alot. It's a little bit confusing but so nice once you get used to it.

Posted on 2002-07-26 17:52:59 by JimmyClif
This example should work for what you want to learn! it is just to sad that an administrator of the forum can't be more helpful then that! I am woundering why he even bothered to reply if that is all the help he is going to give?


Flames hurt but not giving help when asked hurts more then all of the FLAMES
Posted on 2002-07-26 18:40:27 by bitfiddler
because I'd wanted him to see if he could have the aha-erlebenis from the declaration.
It's my belief people will learn more by figuring things out for themselves, given the proper aid.

If he'd just said no I'd given him more pointers, such as the FAQ and what he was looking for.

give a man a fish...
Posted on 2002-07-26 18:46:39 by Hiroshimator
To a Newbie LPCTSTR is meaning less...
he did not even know this by his question.

Now Hiroshimator, did you learn from your

Posted on 2002-07-26 18:50:23 by Zcoder
Geez guys, give Hiroshimator a break.

He's trying to get the guy to help himself a little.

It's not like he was *denying* him help.

Posted on 2002-07-26 19:02:17 by chorus
Well I appoligize!

I was just trying to get someones ATTENTION when a NEWBIE asks for help they don't want to be belittled anymore then they are just asking a simple question! Obviously they came here thinking that all of the older more wise programmers would know this so it wouldn't be a really big chunk out of their A## to give a good answer to the question asked! I would think that if he returns after the chidding he took that would be real fortitude on his part!

Posted on 2002-07-26 19:09:36 by bitfiddler

"Give a man a fish, and you feed him for a day. Teach a man to fish, and you feed him for life."

I'm sorry, I don't see hiroshimator doing anything wrong, nor belittling the guy.
His help/hints were a little vague, yes, and probably not enough for a utter
newbies to go from - but the idea is good. It is so much better to help people
help themself, rather than giving them ready-made examples. You learn more
from figuring out things yourself (possibly with help from others), and nothing
beats the a-ha! feeling when you have solved a problem (more or less) on your own.

Give hiroshimator a break.
Posted on 2002-07-26 19:22:37 by f0dder

You want NEWBIES to find it on their own?
We might as well close the forum then.

I am here to help others, and not stick up for others.
I don't care who you are I will help you IF I can
and I don't care who you are, IF your wrong, your
just WRONG....

NEWBIES can not sort out what you think they can

Posted on 2002-07-26 20:38:31 by Zcoder
zcoder, you got me wrong. I don't want newbies to "find it on their own".
I want them to put in an effort, with some help from the rest of us.
There's quite a difference. Spoonfeeding is for babies... the rest of us go
from hints and similar. I don't want 'newbies' to feel as NEWBIES, I want
them to feel like normal people who are starting on a new task. They have
something new ahead of them, but they don't need to be treated as morons -
they are individuals with the capability to *think*, *reason* and *search*.
Give them some clues and some help, and if they can't make their way, give
them some more. It's like with an adventure game... if you're stuck, do you
want the full walkthrough, or a few hints?
Posted on 2002-07-26 21:16:14 by f0dder
@ chorus: Big thx! :) Now I got it!
@ Hiroshimator: In some way you are right, but I'm really a newb and so like bitfiddler said "To a Newbie LPCTSTR is meaning less...".
For that example: I know that a LPCTSTR is needed, but where did I get the information how to create one? I know how to define a lpStr when its initialized: .data test db "lalaal",0 , but I didn't knew how to create one that is uninitialized. And the question is: Where do I get this information? I study Icz-Tuts, but he doesnt clear out the details (i.e. whats a 0-termed-string etc)
So is there any other useful link, that take care of that in depth?
(Or probably a book?)

But one more @ chorus:
"If he'd just said no I'd given him more pointers, such as the FAQ and what he was looking for."
Since you were a newb yourself, you should know how frustrating it is, if you don't get the easiest stuff work, and when s.b. just give you some clues ;)
But at the other hand I think its the best way to teach the poeple (like me) how to learn stuff autonomous (sorry for my bad english :( just another word caught out the dictionary) and don't have to ask every time. But if there are still so much gaps that doesnt really help cause I don't know where to start.

PS: Plz take care of the red-marked ;)
PPS: I'm not just a little kid want to show how cool it is to code in asm... I'm really interested and fascinated from this language and happy about every little help :)
Posted on 2002-07-27 04:43:22 by Subby
you're welcome. I hope that what I posted helped. Most of us are here to help (including Hiroshimator), but we also encourage people to understand their errors and learn how to find the information themselves.

For instance, I downloaded the example that bitfiddler posted, and although it contained the correct code, it didn't provide any answers. While I appreciate the effort of his post, what we try to avoid on this board is people going "How do I do xxx?" and somebody giving them a cut-and-paste solution. In this case, however, I had already posted the reasoning behind it so bitfiddler's example was appropriate.

BTW, I never said this, but I understand the point you are trying to make:

"If he'd just said no I'd given him more pointers, such as the FAQ and what he was looking for."

Hiroshimator did. And it get's right to what we've been saying. Hiroshimator asks "Do you understand the nature of your error". If you had replied "no" he would have given you more help.

As for intro tuts... I can't think of one at the moment. There's always Art Of Assembly by Randall Hyde but it's not really for Win32. I think for stuff like type declarations etc we (others on the board) have learned them by learning C++ or what have you. I'll try and dig up some actual links but for now, it's off to work :)

Posted on 2002-07-27 07:48:50 by chorus

What do you think of that books:
(Don't know if they are avaiable in English)


Posted on 2002-07-27 07:54:08 by Subby
These two links are probably the best for beginners (in my opinion):

Steve Gibson's: http://grc.com/smgassembly.htm
Look for his Small Is Beautiful example

Wayne Radburn's http://webster.cs.ucr.edu
Check out his various Skeleton reincarnations

Both of these links I've pulled off of Iczelions links http://spiff.tripnet.se/~iczelion/links.html
I would also check out Hutch's homepage http://www.movsd.com and other member's sites. Although you'll mostly find each member's site is specifically geared toward one aspect of assembly language. (Ex., Ernie's site has a lot to do with COM in ASM... not a beginner topic...)

As for books... I've only bought one ASM book ever. It was Master Class Assembly Language by WROX press. It was very good, but I think that there's enough resources on the net to learn win32asm without buying a book. Although some people might debate this.


P.S. If you haven't already, check out the FAQ forum. It's pretty new, but I'm sure will prove useful.
Posted on 2002-07-27 08:18:41 by chorus
Bitfiddler that is a very nice mouse prog.

So i guess if you want client area coordinates instead you would do a:


mov ebx, rect.left

GetCursorPos, addr mousept....and then what?

Whats the easiest way to perform the subtraction is my question. It has to be done before converting to ascii.
Posted on 2002-07-27 17:26:00 by IwasTitan
There's actually no reason to call GetCursorPos if you want the client coordinates as they are provided to you in lParam.
Suppose you want eax to be the x-coord and edx to be the y-coord:

movzx eax,WORD PTR [lParam]
movzx edx,WORD PTR [lParam+2]

Easy as that

Posted on 2002-07-27 17:35:51 by chorus