how to run the program only once (windows)

Share your advanced PureBasic knowledge/code with the community.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

hmmm... does that mean datasection is always maintained in memory, or no, perhaps better put: does that mean that the address you pass from one program to another is valid and stays valid? i thought you couldn't rely on 'physical' adresses being the same to all programs... or is this ok these days on windows?
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Dr. Dri
Enthusiast
Enthusiast
Posts: 243
Joined: Sat Aug 23, 2003 6:45 pm

Post by Dr. Dri »

When you use adresses (for example a label) this adress refers to your process. So if it's the same program (what i know from the ExeFile) 2 identic adresses point to the same data.

I think this is "relative" adressing but i don't really know. :roll:
I don't know neither if you can get the physical adresses

Dri
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

now let's up the challenge: let's create two DIFFERENT programs that need to access the same data :-) preferably by allocating a piece of fixed memory?

i've been looking through the win32 api and i'm pretty sure there must be some way, but haven't found it yet...
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

That's a good challenge.

Would FileMapping (CreateFileMapping, OpenFileMapping) be a way to go?
@}--`--,-- A rose by any other name ..
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

There is already a userlib for this I think : GlobalSharedMemory (by Rings) http://pbosl.purearea.net/index.php?site=Libs . It uses file mapping IIRC.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

ha solved it :-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

it's also another alternative to check what program came first, just see if you can open a filemapping, if not there's no instance running yet :-)

see here...

viewtopic.php?t=17542
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

I still don't know what's wrong with the single-line sempahore example, it
works just fine for me with Win 98se, ME, 2K and XP. (I couldn't make it
fail under Win98se as reported here, maybe the steps to make it do so
could be posted so I can see for myself?).
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Dr. Dri
Enthusiast
Enthusiast
Posts: 243
Joined: Sat Aug 23, 2003 6:45 pm

Post by Dr. Dri »

@PB
I said i tried semaphore, mutex and if the program crash, the semaphore or the mutex still exists and you can't launch the program again.
That's what happenned to me (win98 se)

Dri
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

That's what I did too -- a sempahore under Win98se and I made the app
crash (by doing a GetClipboardText when the clipboard had >64K) and
I was still able to re-run it again, thus I believe the semphore died when
the app crashed. Anyway, that's my experience with it, and why I still
choose to use it to prevent multiple instances. <Shrugs>.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

an laternative may be a named pipe, playing with that now
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Post Reply