Ok, I have a question. In your coinvoke you have:
mov edx, pInterface
mov edx,

Now, I'm new to assembly, and ever newer to com--why didn't you just:
mov edx,

????
Posted on 2001-08-28 18:04:12 by Kenny
Your thinking of:
mov edx, OFFSET pInterface
mov edx,

---------
mov edx, pInterface ;moves the contents, not the offset.
mov edx,
Posted on 2001-08-28 18:25:24 by bitRAKE
ok, NOW I'm confused...

If pInterface == 1
mov edx, pInterface ;edx == 1
mov edx, ; what does edx equal now?

What if I were to just do

mov edx, ;What would that do?

I'm still newbie, and very confused :)
Posted on 2001-08-28 18:28:51 by Kenny
Kenny,

I understand your confusion, as I was stuck on this very point when starting to use MASM.



When you say:



mov edx, pInterface


you're telling the compiler to take the address held by the label 'pInterface' and load the contents to edx.



On the other hand, when you say:



mov edx, [pInterface]


you're telling the compiler to take the address held by the label 'pInterface' and load the contents to edx.




...wait a sec.... HUH?

Oh yep, it's the same thing. MASM 'assumes' the brackets for you there. It's a 'feature.'



To override it, you have to say:



mov edx, OFFSET pInterface


and then you get the value of the label, ie, the address. In this case, you get a pointer to a pointer.


Now in a coinvoke call, address 'pInterface' holds the address of the function to call. That's why it is two steps:



mov edx, [pInterface] ; get the pointer at address pInterface
mov edx, [edx] ; then get the value pointer to, the
; address of the function to call
call edx ; do the class method
Posted on 2001-08-28 18:43:36 by Ernie
Kenny, I didn't mean to make light of it. There have been many discussions on this board about this very thing and how wrong it is, and how it makes learning asm with MASM a pain in the backside. I think this is one of the hinge points that lead to the creation of NASM! I don't think it logical - which asm syntax certainly should be, but it is the way it is. :(
Posted on 2001-08-28 19:00:24 by bitRAKE
naw, it's cool man. I really don't mind. I'll just chock this one up on the microsoft blame board :)

But, I'm still pretty confused so I'm gonna go searching on the internet for some good examples that explain this sort of thing. Got any suggestions?
Posted on 2001-08-28 19:05:40 by Kenny
Kenny:

i have a suggestion which will help you. if you have troubles open a dummy project and type all the scenarios in masm32 and then go to Tools->Dis-assembe EXE file. check out the disassembly below.

mov edx, pInterface
mov edx,

mov edx,[403000h]
mov edx,

mov edx,

mov edx,[403000h]

mov edx, OFFSET pInterface
mov edx,

mov edx,403000h
mov edx,

dr phil :)
Posted on 2001-08-28 19:14:06 by phil
Ok, so "403000h" is the address of pInterface? No?

So why do we need to move edx into edx, if the brackets don't mean nothing?
Posted on 2001-08-28 19:24:17 by Kenny
See, that is where the consistancy falls apart. Registers are handle opposite. :eek: Brackets are required because wihtout them your just moving the number in the register around. With them the number in the register is an address and you get the value at that address.
Posted on 2001-08-28 19:42:09 by bitRAKE
What does that mean?

I don't get it... I've coded fine in assembly until now. Why all of a sudden does it feel like I don't know anything anymore :)
Posted on 2001-08-28 19:43:32 by Kenny
I'm starting to understand now:

mov edx, pInstance ; pInstance holds the address for the data you want.
mov edx, ; This moves the data the address of edx into edx. Or in other words, moves the data from the address of pInstance into edx?

Am I right?

If I am, then why not use the offset

mov edx, offset pInstance ; Moves the data from the address of pInstance into edx... What's different about this?

I know this is what you said already bitRAKE, but it just took me a while :) lol, now I want to know why

:alright:
Posted on 2001-08-28 20:20:04 by Kenny
1: yes "403000h" is the memory location of the pInterface variable.

2: consider this:

mov edx, 403000h
mov edx,

after those execute what is edx equal to? is it equal to 403000h? NO. its equal to what is at address 40300h or [403000h]... which is "1" or whatever you happen to set pInterface equal to in your example.

dr phil :)
Posted on 2001-08-28 20:23:16 by phil
So why not use mov edx, offset pInterface.

I'm pretty sure that would make edx = 1. If not, I'm gonna make the dummy project like you said :) lol
Posted on 2001-08-28 20:26:00 by Kenny
mov edx, pInstance ; pInstance holds the address for the data you want.
mov edx, ; This moves the data the address of edx into edx. Or in other words, moves the data from the address of pInstance into edx?


You are right. Maybe a clearer way to say it is:

This moves the data pointed to by edx to edx.

I like the brackets, they make it easy to see like a box[](in this case, labeled edx) and you are looking into it and moving what you find to edx.
Posted on 2001-08-28 20:40:49 by ThoughtCriminal
kenny:

take a close look at the red dissassembly below: you will notice that 'offset pInterface' is the same as writting '403000h'. you will not end up with '1' unless you follow it up with mov edx, .

mov edx, pInterface
mov edx,

mov edx,[403000h]
mov edx,

mov edx,

mov edx,[403000h]

mov edx, OFFSET pInterface
mov edx,

mov edx,403000h
mov edx,

now back to your original question where you start with:

mov edx, pInterface
mov edx,

if you wanted to use:

mov edx, OFFSET pInterface
mov edx,

this is perfectly valid but is ONLY equal to:

mov edx, pInterface

so you *still* need the next part of code which is a second:

mov edx,

dr phil :)

ps what does dereferencing a pointer or a pointer to a pointer look like in assembly?
Posted on 2001-08-28 20:55:51 by phil
Dang ok... Back to the drawing board :)

I'll get to the bottom of this one! I want to make coinvoke faster :)

----------------------

So Ernie, what's stopping you from doing this instead:
mov edx, pInterface

Do you not know where pInterface is or something? I would think that it would be faster. (well maybe not because of pairing)

Well, as I sit and look at Phil's dissassembly, I notice I'm having a horrible day. To make a long story short, I haven't had much sleep in a while now, and because of another long story, I lose memory when I'm tried :)

So, thanks so much for clearing this up. I think I finally got it! I remember how it goes now :) lol
Posted on 2001-08-28 21:02:13 by Kenny
Kenny:

don't sweat it... i have plenty of horrible days too. we're all here to help each other out on those days.

dr phil :)
Posted on 2001-08-28 21:21:06 by phil
Kenny,

First, trust me that coinvoke is as short and efficient as it can be. As it MUST be.

I'll write you a description tomorrow (I tried tonight and had too many errors in it to leave posted).

Kenny, keep asking questions till this point is (as my EE102 prof used to say) IN YOUR BLOODSTREAM, else you will never make much sense of asm stuff.

Good luck.
Posted on 2001-08-28 22:12:34 by Ernie
Ok, I just read it three times in a row and I still went "huh?" Why does Microsoft have to elaborate simple things? But anyways, I will keep asking questions until I get it. (You just made more.)

After I read it about 10 more times I'm gonna ask them.

There are two rules I learn by, and the first one is:
If I don't know, ask.
If I don't know try and figure it out, and keep asking until I understand it.

So, until I read it about 10 more times...
Posted on 2001-08-28 22:31:46 by Kenny
dang! you deleted it! Ok, whatever. I'm gonna just play with some source or somerthing. Heck, I've already crashed my program like 6 times tonight writing other code and made about 300 memory leaks, so it can't get much worse. :)
Posted on 2001-08-28 22:34:21 by Kenny