Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DLL Talk / Shared memory mutex

Author
Message
EDGECOM
13
Years of Service
User Offline
Joined: 7th Sep 2006
Location: US
Posted: 9th Jul 2010 00:49
IanM I guess this is for u :p

ok I can't for the life of me get this to share..

if you compile and run the code below it will error

However....




if you make the code look like this it will work




and so going by the working code above I should be able to share info right? wrong.... if I call the function listed below from the other exe I get

Runtime Error - Bank XX Already exists at line XXX



so my question is do I need to make some other call and could someone show me working code cause I have tried the following

1. I have tryed to unlock and lock system object IE unlock before the call then locking it after words

2. Elevating both exe's to debug status

3. Elevating both exe's to debug and linking both threads via the kernel32.dll

4. making a include with a #constant that didn't do much good cause when each exe loads the include file an exclusive memory chunk for that particular exe

one thing I did get to work is by loading the kernel32.dll and calling ReadProcessMemory the only problem with this method is every time I update or change the exe I would need to re caculate the offset to the memory I want to read

A side note you can not make more than one shared object or shared memory if you do it will error sayign the object or bank already exists

also calling GET SYSOBJ NAME$( Object Number ) from the same exe where the object does exist will error and state that the object does not exist when you can run SYSOBJ EXIST( Object Number ) and it will = 1

so I don't know whats going on I have DBP v 1.074 and xp is fully up to date
IanM
Retired Moderator
17
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 9th Jul 2010 02:42
First, let's deal with a working example - it's in the attachment.

The 'host' program is one that generates a new string once per second and writes it into the bank.
The 'client' program simply reads the string from the bank every loop.

Compile both programs into exe's, then run the host program, and then immediately run the client program.

Quote: "A side note you can not make more than one shared object or shared memory"

That's demonstrably false:


Quote: "also calling GET SYSOBJ NAME$( Object Number ) from the same exe where the object does exist will error"

That's definitely a bug - the next release of my plug-ins will include the fix.

Attachments

Login to view attachments
EDGECOM
13
Years of Service
User Offline
Joined: 7th Sep 2006
Location: US
Posted: 9th Jul 2010 08:06
Quote: "A side note you can not make more than one shared object or shared memory"

sorry,
About that I was trying to write it like this thats what I get for messing with it when I was tired and thank you for the example

I also had a feeling I was not locking and unlocking propperly



so the object never got created therefor FIND FREE SYSOBJ() and FIND FREE SYSOBJ() would always return = 1


here is the working version of that

Server:



Client:
IanM
Retired Moderator
17
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 9th Jul 2010 13:49
Why create a different bank for each piece of information? I'd put it all in one bank in this instance - in fact I'd probably put it all into a single bank, unless I was communicating different pieces of information to different programs.

Depending on the pieces of information being updated, then it still might make sense to have multiple mutexes.

EDGECOM
13
Years of Service
User Offline
Joined: 7th Sep 2006
Location: US
Posted: 9th Jul 2010 14:10
I know lol I was just messing arround with it I made a mini shared static database that 4 exe's queried info from it

and yes I would use one for 2 exe's and just use the FIRST TOKEN$(source, delim) and NEXT TOKEN$(delim) to get info from the string
IanM
Retired Moderator
17
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 9th Jul 2010 17:34
I was suggesting something even simpler - put your first string at 0 for 256 characters, then your second string at 256 for another 256 characters, then any further fields after that etc.

EDGECOM
13
Years of Service
User Offline
Joined: 7th Sep 2006
Location: US
Posted: 10th Jul 2010 02:14
that would be good also

but wouln't it crash (is there a limit on positions per address) or overlap other memory or does it auto realloc memory

err at this point I think it would be based on how much ram you have right if you want I can make a app and see if I can crash my comp IE find a end lol or use up all my ram + page file would be aswome

how long would it take to fill 4gig of ram prob not long...
IanM
Retired Moderator
17
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 10th Jul 2010 04:59
Ok, I think you're getting confused

Here's what I mean:
1. Allocate a bank of 512 bytes.
2. Write the first string from 0 to 255.
3. Write the second string from 256 to 511.

No overlapping, no reallocation, no using up all memory, no filling up the page file.

If you have extra data then make the shared memory block larger and continue to use unused portions - eg, if you wanted to add an integer value, make the bank 516 bytes in size, then write the integer to position 512.

Login to post a reply

Server time is: 2019-10-19 08:32:55
Your offset time is: 2019-10-19 08:32:55