Archive: Stack and SimpleSC: service functions question


Stack and SimpleSC: service functions question
  Hi all, a question about NSIS stack and SimpleSC: (service control) functions.

It seems you have to Pop the result in a variable to get the function return value .

What if I have

Push $0

SimpleSC:<call>
Pop $0

Pop $0


Does this sequence screw the stack or the initial $0 value?

Thanks,
Mario

No - the stack and the initial $0 you pushed should be fine. However, that does depend on whether or not the plugin behaves. Easy enough to find out: try :)


I posted because I tried before and there's something strange :)

I have a for next loop with $0 as loop variable running from 1, and $0 is set back to 1 after each loop iteration (thus there's an infinite loop). But the loop contains all sequences as shown above, triple checking again...

- Mario


Well, from peeking at the Simple Service Plugin's page.. there are several calls that place more than one item on the stack; ::GetServiceFailure places 9 items on the stack, for example. So double-check how many items the call you're using might be placing on the stack.


Just to elaborate... I often put comments in my code when there's stack operations to that I can keep track of them.. might be useful for you to do so as well.

Let's say you're calling ::ServiceIsRunning...

/* presuming $0 is your counter */

>Push $0 ; Stack: $0:counter
SimpleSC
::ServiceIsRunning "MyService" ; Stack: errorcode running $0:counter
Pop$0 ; $0 = errorcode ; Stack: running $0:counter
Pop$1 ; $1 = running ; Stack: $0:counter
Pop$0 ; $0 = $0:counter ; Stack: -empty-
Additionally.. if you're afraid of stack/variable corruption, it might be useful to just make your own variable...
***91;...***93;

Var /global counter
StrCpy $counter 0
IntOp $counter $counter- 1
>***91;...***93;
...so that you don't have to worry about what plugins/macros/you do to the stack and NSIS's predefined variables.
It will add a smidgen of memory use and filesize to your installer, but the more I'm working with NSIS, the more I'm finding myself using my own variables to keep code semi-readable :)

Ok, using my own loop variable it works as expected - :\

Now checking why the SimpleSC calls seem to return bogus values, but that's another story...

- Mario