Call function in another executables address space
-
- Posts: 104
- Joined: Apr 30, 2009 15:20
- Location: Dumbarton, Scotland
Call function in another executables address space
Is this possible, can it be done in freebasic, how could I go about doing it?
-
- Posts: 8586
- Joined: May 28, 2005 3:28
- Contact:
Re: Call function in another executables address space
Why not ?wolfman775 wrote:Is this possible, can it be done in freebasic, how could I go about doing it?
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
-
- Posts: 104
- Joined: Apr 30, 2009 15:20
- Location: Dumbarton, Scotland
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)
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)
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.
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.
-
- Posts: 104
- Joined: Apr 30, 2009 15:20
- Location: Dumbarton, Scotland
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.
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.
Might give you another possibility: http://www.cyberciti.biz/tips/what-is-d ... usage.html
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