Call function in another executables address space

Linux specific questions.
Post Reply
wolfman775
Posts: 104
Joined: Apr 30, 2009 15:20
Location: Dumbarton, Scotland

Call function in another executables address space

Post by wolfman775 »

Is this possible, can it be done in freebasic, how could I go about doing it?
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Call function in another executables address space

Post by D.J.Peters »

wolfman775 wrote:Is this possible, can it be done in freebasic, how could I go about doing it?
Why not ?
if your executable exports something you can use DyLib in same way as it would be a dynamic lib with exported things.

http://www.freebasic.net/wiki/wikka.php ... gDylibload
http://www.freebasic.net/wiki/wikka.php ... ylibsymbol

Joshy
wolfman775
Posts: 104
Joined: Apr 30, 2009 15:20
Location: Dumbarton, Scotland

Post by wolfman775 »

I tried loading the executable like any other lib with DyLibLoad but it just returns 0, and calling the function causes a segfault :(

Edit:
Realy what I would like is to have a dynamic library in its own adress space, so that multiple executables can communicate through it (At the moment if the both load the same library it is copied into that programs adress space meaning that if one program sets a shared variable in the lib through a function the other executable cannot read that value)
Landeel
Posts: 777
Joined: Jan 25, 2007 10:32
Location: Brazil
Contact:

Post by Landeel »

Well, it's not a trivial task...

Each executable will have the dynamic library in a separate space.

I can think of 2 possible workarounds:

1) You can get the executables to comunicate with each other using temporary files

2) You can make the first executable run the second one using "open pipe"

As FreeBasic only support unidirectional pipes, you may need to combine the two techniques.

In both cases, variables won't be magically shared between them, you will have to write code for that.
wolfman775
Posts: 104
Joined: Apr 30, 2009 15:20
Location: Dumbarton, Scotland

Post by wolfman775 »

This is going to take a lot of thinking, because neither of those methods are flexible enough, mostly because I am going to have multiple executables communicating bi-directionally and I am already using the pipe method for something else (Getting a window handle so I can use XReparentWindow) I might just need to implement it using some network protocol the same way XLib does...

Even worse, I will have to do that in multiple threads and I am trying to avoid that because my program is complex enough as it is. If only this could be a lot easier...

I could have a bunch of files (one per app) that contain info that is to be exchanged, and when an app is started then it will be given a file to use and then I could have a list of these files somewhere (An array?), then when an app exits, it must manually delete that file and remove it from the list so it doesn't waste processor time, and even then I am trying to avoid temporary files, so sockets it is...

/Rant

Hopefully someone finds this rant useful.
Landeel
Posts: 777
Joined: Jan 25, 2007 10:32
Location: Brazil
Contact:

Post by Landeel »

Ouch, that's complex. I think you will have to go with networking then.

In the past I remember reading about a library for DarkBASIC (Windows only), that would share a memory space between 2 applications.

I have never seen such a thing in FreeBASIC, or in Linux.
cha0s
Site Admin
Posts: 5319
Joined: May 27, 2005 6:42
Location: USA
Contact:

Post by cha0s »

Might give you another possibility: http://www.cyberciti.biz/tips/what-is-d ... usage.html
sir_mud
Posts: 1401
Joined: Jul 29, 2006 3:00
Location: US
Contact:

Post by sir_mud »

Try zeroMQ, this is one of the things it was designed for. Header for freebasic available here http://code.google.com/p/freebasic-head ... zmq/zmq.bi
Post Reply