It is currently Wed Jun 19, 2013 6:28 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Finding unique ID for each caller to a procedure
PostPosted: Thu May 10, 2012 4:01 pm 
Offline
Enthusiast
Enthusiast

Joined: Sat Sep 11, 2004 11:54 am
Posts: 416
Location: UK
Is there a way for a procedure called from many places in a program to determine a unique signature for each caller (without passing some form of ID in the call to the procedure)?

If this was a program written in assembler I could inspect the return address on the stack and use that. Is there a way of doing something similar in PB (Microsoft only) ?

I want to re-instate various parameters (Eg: A the position of a window opened by the procedure) to match the parameters established the last time it was called.


Top
 Profile  
 
 Post subject: Re: Finding unique ID for each caller to a procedure
PostPosted: Thu May 10, 2012 4:17 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Thu Jan 10, 2008 1:30 pm
Posts: 720
Location: Germany, Glienicke
i don't know if it right, but this code looks good:
Code:
Procedure Test(Parameter.i)
   Protected Address.i
   ! MOV eax, [esp+4]
   ! MOV [p.v_Address], eax
   Debug "Call from: "+Str(Address)
EndProcedure


Test(0)
For n = 1 To 3
   Test(n)
Next
a=b
Test(7)

_________________
Image


Top
 Profile  
 
 Post subject: Re: Finding unique ID for each caller to a procedure
PostPosted: Thu May 10, 2012 5:07 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Aug 15, 2009 6:59 pm
Posts: 1028
STARGÅTE wrote:
i don't know if it right, but this code looks good:
Code:
Procedure Test(Parameter.i)
   Protected Address.i
   ! MOV eax, [esp+4]
   ! MOV [p.v_Address], eax
   Debug "Call from: "+Str(Address)
EndProcedure


Test(0)
For n = 1 To 3
   Test(n)
Next
a=b
Test(7)

Yes, just use the return address as ID.


Top
 Profile  
 
 Post subject: Re: Finding unique ID for each caller to a procedure
PostPosted: Mon May 14, 2012 11:29 am 
Offline
Enthusiast
Enthusiast

Joined: Sat Sep 11, 2004 11:54 am
Posts: 416
Location: UK
Gentlemen,

Thanks for your suggestions. My experience with assembler level coding on Intel processor is a very small fraction of zero! Despite writing all manner of stuff on 65xx processors, including assemblers, I have never dabbled with the equivalent on PCs. Would you kindly suggest the reason why I get the following message when I try to compile the above code:

MOV [P.v_address],Eax
error: undefined symbol 'P.v_address'

Thank you
Richard


Top
 Profile  
 
 Post subject: Re: Finding unique ID for each caller to a procedure
PostPosted: Mon May 14, 2012 12:50 pm 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Sat Apr 26, 2003 8:27 am
Posts: 4231
Location: Strasbourg / France
I think it's a case issue.

It should be p.v_Address and not P.v_address.

_________________
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).


Top
 Profile  
 
 Post subject: Re: Finding unique ID for each caller to a procedure
PostPosted: Mon May 14, 2012 1:22 pm 
Offline
Addict
Addict

Joined: Wed Aug 24, 2005 8:39 am
Posts: 2573
Location: Southwest OH - USA
Something like this?

http://www.purebasic.fr/english/viewtopic.php?p=238692


Top
 Profile  
 
 Post subject: Re: Finding unique ID for each caller to a procedure
PostPosted: Mon May 14, 2012 4:10 pm 
Offline
Enthusiast
Enthusiast

Joined: Sat Sep 11, 2004 11:54 am
Posts: 416
Location: UK
Thanks gnozal...
Absolutely right.
It now works and I have the key feature needed to go forward with.

I note that the original post from Stargate had a lower case 'p', and when I copy and paste into jaPBe it changed to an upper case 'P'. :?

Two other source files were open in the editor and one used 'P' as a variable... and the editor thought it was doing me a favour!
Could this be a possible tweak for jaPBe to not modify the case of variables in an assembler source section?

Richard


Top
 Profile  
 
 Post subject: Re: Finding unique ID for each caller to a procedure
PostPosted: Tue May 15, 2012 8:13 am 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Sat Apr 26, 2003 8:27 am
Posts: 4231
Location: Strasbourg / France
RichardL wrote:
...Could this be a possible tweak for jaPBe to not modify the case of variables in an assembler source section?
I have uploaded a new jaPBe build.
It should not change the case of a variable immediately following an ASM keyword (note : for the ASM keyword to be recognized by jaPBe, it must follow the '!' without any space [!MOV = Ok, ! MOV = not Ok]).

_________________
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).


Top
 Profile  
 
 Post subject: Re: Finding unique ID for each caller to a procedure
PostPosted: Tue May 15, 2012 10:17 am 
Offline
Enthusiast
Enthusiast

Joined: Sat Sep 11, 2004 11:54 am
Posts: 416
Location: UK
Good morning,

@gnozal... thanks for the jaPBe update. The best just gets better!

However... I have found a problem / done something stupid.
Code:
Procedure Test(z)
  Protected Address.i
  ! MOV Eax, [Esp+4]
  ! MOV [p.v_Address], Eax
  Debug "Call from: "+Str(Address)
EndProcedure

Procedure Test2(z$)
  Protected Address.i
  ! MOV Eax, [Esp+4]
  ! MOV [p.v_Address], Eax
  Debug "Call from: "+Str(Address)
EndProcedure

Test(1)

For n = 1 To 3
  Test(2)
  Test(3)
Next
a=B
Test(4)

Debug ""

p$ = "hello"
Test2(p$)
For n = 1 To 3
  Test2(p$)
  Test2(p$)
Next
a=B
Test2(p$)


On my machine (Windoze7) Test2 reports each Address as zero.


Top
 Profile  
 
 Post subject: Re: Finding unique ID for each caller to a procedure
PostPosted: Tue May 15, 2012 10:37 am 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Sat Apr 26, 2003 8:27 am
Posts: 4231
Location: Strasbourg / France
RichardL wrote:
On my machine (Windoze7) Test2 reports each Address as zero.

It' because of the string parameter.
Code:
Procedure Test2(z$)
  Protected Address.i
  !MOV Eax, [Esp+8]
  !MOV [p.v_Address], Eax
  Debug "Call from: "+Str(Address)
EndProcedure

_________________
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).


Top
 Profile  
 
 Post subject: Re: Finding unique ID for each caller to a procedure
PostPosted: Tue May 15, 2012 10:54 am 
Offline
Enthusiast
Enthusiast

Joined: Sat Sep 11, 2004 11:54 am
Posts: 416
Location: UK
Hi gnozal,

I was rather hoping that this was a simple way to determine some form of caller ID, but it looks like I'm treading on dangerous ground, so maybe it is better to put this problem aside until I can find the time to find out what is really going on.

Thanks for your assistance.

Richard


Top
 Profile  
 
 Post subject: Re: Finding unique ID for each caller to a procedure
PostPosted: Tue May 15, 2012 11:14 am 
Offline
Addict
Addict

Joined: Sun Aug 08, 2004 5:21 am
Posts: 1108
Location: Netherlands
You could pass an ID yourself for a procedure that needs one
Code:
Procedure myFn(callerID.i, arg.s)
  Debug "Call from: " + Str(callerID)
  Debug "arg:" + arg
  Debug ""
EndProcedure

Procedure Caller1()
  myFn(@Caller1(), "argument from caller 1")
EndProcedure

Procedure Caller2()
  myFn(@Caller2(), "argument from caller 2")
EndProcedure

Caller1()
Caller2()


Top
 Profile  
 
 Post subject: Re: Finding unique ID for each caller to a procedure
PostPosted: Tue May 15, 2012 11:28 am 
Offline
Enthusiast
Enthusiast

Joined: Sat Sep 11, 2004 11:54 am
Posts: 416
Location: UK
Hi Wilbert,
Yes, I know, but please see line one of my first post... I'm trying to assign an identify to a caller of a Procedure() without the caller sending me an explicit ID.

The reason for this is that I'm producing a complex requester that is called from many places in a large program and I want to reset the position of the requester, and some option items in it, to match the last time it was called from each place. This way the user does not need to re-position the requester etc each time it is used.

Also, I'm most likely going to use the requester in other applications and I would like to solve the problem just the once and from then on I can forget about ID's etc.

Richard


Top
 Profile  
 
 Post subject: Re: Finding unique ID for each caller to a procedure
PostPosted: Tue May 15, 2012 11:30 am 
Offline
User
User

Joined: Thu May 03, 2012 1:24 pm
Posts: 29
maybe will work this(i haven't the possibility to check if work)


Code:
 Macro MYcallID
   Protected Address.i
   ! MOV eax, [esp+4]
   ! MOV [p.v_Address], eax
   Debug "Call from: "+Str(Address)   
 EndMacro



 Procedure Test(Parameter.i)
   MYcallID
 EndProcedure

Procedure Test2(Parameter$)
   MYcallID
 EndProcedure


Test(1)

For n = 1 To 3
  Test(2)
  Test(3)
Next
a=B
Test(4)

Debug ""

p$ = "hello"
Test2(p$)
For n = 1 To 3
  Test2(p$)
  Test2(p$)
Next
a=B
Test2(p$)



i done only one modification on your script


Top
 Profile  
 
 Post subject: Re: Finding unique ID for each caller to a procedure
PostPosted: Tue May 15, 2012 11:51 am 
Offline
Addict
Addict

Joined: Sun Aug 08, 2004 5:21 am
Posts: 1108
Location: Netherlands
RichardL wrote:
please see line one of my first post...

Sorry, I overlooked that :oops:


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: IceSoft and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye