Hi guys,

I'm fairly new to NT programming. I'm writing a program in which I want to load the offset of an other routine's sub routine to EAX. In 9x this is no problem: "MOV EAX, OFFSET subroutine" works ok of course. But in NT my MASM doesn't recognize the label 'myroutine' anymore. For Example:

.386
.MODEL FLAT, STDCALL
OPTION CASEMAP:NONE ;my init params

routine1 PROC
...
...
subroutine1:
...
...
routine1 ENDP

routine2 PROC
MOV EAX, OFFSET subroutine1
RET
routine2 ENDP

compiling this gives me the error: 'undefined symbol 'subroutine1'. I'm sure this is a stupid question, but I just don't know how to refer to my subroutine without some 'workaround' like calculating the offset from subroutine1 to routine1 manually and then adding this to the offset of routine1 to refer to subroutine1.
Thanks in advance,
Dante
Posted on 2002-02-06 07:30:01 by _dante_
subroutine1 is a label, so already an address, I think offset is useless here... try without it...
Posted on 2002-02-06 07:42:02 by JCP
Try Readiosys's solution first, if that doesn't work then make sure you have routine1 declared as a proc at the top of your sourcefiles.
Posted on 2002-02-06 14:44:47 by sluggy
Thanks guys, but removing the 'offset' doesn't help, still the same error.

Sluggy, how do I declare the proc at the top of the source ? Could you give an example please ?
thanks a lot,

dante
Posted on 2002-02-06 15:13:47 by _dante_
You have to use a double colon on labels within a PROC to make them public, or use the OPTION command (can't remember which one off the top of my head) to make all lable within a PROC public (this isn't a good idea).
routine1 PROC 

...
subroutine1[b]::[/b] ; this lable is public outside of PROC
...
routine1 ENDP

routine2 PROC
MOV EAX, OFFSET subroutine1
RET
routine2 ENDP
Posted on 2002-02-06 15:39:58 by bitRAKE
Bitrake, yes, this works ! Thanks for sharing your knowledge man !
Posted on 2002-02-07 06:08:38 by _dante_

You have to use a double colon on labels within a PROC to make them public, or use the OPTION command (can't remember which one off the top of my head) to make all lable within a PROC public (this isn't a good idea).


Thanks, bitRAKE! Didn't know this :)
Posted on 2002-02-07 07:18:35 by bazik
Just curious,
Can someone give me a reason why you may want to put the offset of a subroutine into a register?

meaning why would you want to do this:



routine1 PROC
...
subroutine1:: ; this lable is public outside of PROC
...
routine1 ENDP

routine2 PROC
MOV EAX, OFFSET subroutine1
RET
routine2 ENDP
Posted on 2002-02-07 13:12:40 by Sliver
There are many reasons, Sliver. Remember in COM how you have a table of pointers to methods - these are subroutines - programmers have been using pointers to code from the very begining to create dynamic solutions. If you wanted to modify the methods of an object you would need to change the code pointers in the object structure. This is kind of like polymorphism, but much more basic in nature - we work with smaller legos here. ;)

In the above case, you'd have to be very careful to know exactly what is going on with the stack to jump into the middle of a PROC - not very programmer friendly.
Posted on 2002-02-07 14:14:54 by bitRAKE
Sliver, I'm working on a protector that contains some polymorphic code (I wrote it for 9x, I'm converting some parts to NT now)
Posted on 2002-02-07 14:28:12 by _dante_