Home All Groups Group Topic Archive Search About

Interlocked Functions vs VB Reading Current Value

Author
26 Feb 2007 4:28 AM
Desi
I have run into the VB6 nuance where it does not reliably read current value
of a VarPtr exposed variable. I can see the foreign process successfully
incrementing the value all day but my client is not picking up the change. I
tried using Boolean = Variable but without success. Since I will be looking
at this variable from within a loop what would be an efficient API to read
the current value directly from memory?

Thanks

Desi

Author
26 Feb 2007 5:35 AM
Ralph
Show quote Hide quote
"Desi" <nospam@thanks.net> wrote in message
news:Op37$5VWHHA.4832@TK2MSFTNGP04.phx.gbl...
> I have run into the VB6 nuance where it does not reliably read current
value
> of a VarPtr exposed variable. I can see the foreign process successfully
> incrementing the value all day but my client is not picking up the change.
I
> tried using Boolean = Variable but without success. Since I will be
looking
> at this variable from within a loop what would be an efficient API to read
> the current value directly from memory?
>
> Thanks
>
> Desi
>

Its likely quite reliable - it just isn't reading the address you think it
should. <g>
http://vb.mvps.org/tips/varptr.asp
http://support.microsoft.com/kb/199824

Note that all the examples where VarPtr is used productively define very
specific contexts. While I am not sure what you mean by a 'foreign process'
Windows programming in general doesn't allow one to share an 'address'
between processes.

Perhaps if you showed a bit of code and explained more about what you are
trying to do. (Barring the fact it makes no sense, I doubt "Boolean =
Variable" would even compile.)

-ralph
Author
26 Feb 2007 6:17 AM
Desi
O.K. some aircode...

App1

Private SignalHere as Long

Public Sub Any

    Call DoSomeStuff(VarPtr(SignalHere )) 'Call made asynchronous by use of
timers.

    Do

        If SignalHere <> 0 Then do something else...

    Loop

End Sub

App2(different process)

Public Sub DoSomeStuff(ByVal PointerToSignalHere as Long)

    Do

        If Something'sChanged Then InterlockedIncrement PointerToSignalHere

    Loop

End Sub

The "Boolean" example I saw was actually: (Meant as a means to access
SignalHere's actual current value. It did actually compile.)

Public Function TestIt() As Boolean
    TestIt = SignalHere
End Function

By doing this within App2;
    JustALong = InterlockedIncrement(PointerToSignalHere)
I can watch the "previous" value as returned by the function increment.
But like I said, I'm not seeing the value of SignalHere within App1
increase.
If within App1 I call "JustALong =
InterlockedIncrement(PointerToSignalHere)" it does actually reveal the
incremented value, however using that method within a loop I think I'm
needlessly contributing to global warming...

Thanks

Desi
_____________________

Show quoteHide quote
> Its likely quite reliable - it just isn't reading the address you think it
> should. <g>
> http://vb.mvps.org/tips/varptr.asp
> http://support.microsoft.com/kb/199824
>
> Note that all the examples where VarPtr is used productively define very
> specific contexts. While I am not sure what you mean by a 'foreign
> process'
> Windows programming in general doesn't allow one to share an 'address'
> between processes.
>
> Perhaps if you showed a bit of code and explained more about what you are
> trying to do. (Barring the fact it makes no sense, I doubt "Boolean =
> Variable" would even compile.)
>
> -ralph
>
>
>
Author
26 Feb 2007 7:56 AM
J French
On Mon, 26 Feb 2007 00:17:39 -0600, "Desi" <nospam@thanks.net> wrote:

>O.K. some aircode...
>
>App1

A variable in one App cannot be accessed by another App ( well not
without some really heavy work and I don't think you are writing a
games trainer)

Do you /really/ have two Apps ?

If you want to communicate between Apps, sort of sharing a variable
then you can use a single MultiUse AX EXE.
- in one of those module level and Static variables in a .BAS module
are sort of shared.
Author
26 Feb 2007 8:55 AM
Desi
Right you are Mr. French.
I now see what I wasn't comprehending, i.e. the distinction between Threads
within a single Process and Threads residing within different Processes.
Yet another glance at msdn reveals (
http://msdn2.microsoft.com/en-us/library/ms684122.aspx )
/quote/

The interlocked functions provide a simple mechanism for synchronizing
access to a variable that is shared by multiple threads. They also perform
operations on variables in an atomic manner. The threads of different
processes can use these functions if the variable is in shared memory.

/unquote/

(I read that umteen times!)

So, everything was behaving as it is supposed to afterall... I'll have to
look into this shared memory business.

> Do you /really/ have two Apps ?


Actually two instances of the IDE at the moment. My intent was communication
between seperate ActiveX EXE's. Guess I'll have to limit myself to
asynchronous cllbacks.

Thanks for the help guys.

Desi
__________________________

Show quoteHide quote
"J French" <erew***@nowhere.uk> wrote in message
news:45e291ba.4580413@news.btopenworld.com...
> On Mon, 26 Feb 2007 00:17:39 -0600, "Desi" <nospam@thanks.net> wrote:
>
>>O.K. some aircode...
>>
>>App1
>
> A variable in one App cannot be accessed by another App ( well not
> without some really heavy work and I don't think you are writing a
> games trainer)
>
> Do you /really/ have two Apps ?
>
> If you want to communicate between Apps, sort of sharing a variable
> then you can use a single MultiUse AX EXE.
> - in one of those module level and Static variables in a .BAS module
> are sort of shared.
>
>