passing variables between external programme and PB
-
cecilcheah
- Enthusiast

- Posts: 168
- Joined: Wed Jun 04, 2003 8:44 am
- Location: Switzerland
passing variables between external programme and PB
Hi
Can anyone tell me what is the best way to do the following:
PB will send a command to an external programme to fetch a variable value from that programme and use that value to do some stuff.
Will post message alone do? If i use postMessage, how can PB retrieve the answer from that programme and get the value of some variables?
Can anyone give me some pointers?
Thanks
Cecil
Can anyone tell me what is the best way to do the following:
PB will send a command to an external programme to fetch a variable value from that programme and use that value to do some stuff.
Will post message alone do? If i use postMessage, how can PB retrieve the answer from that programme and get the value of some variables?
Can anyone give me some pointers?
Thanks
Cecil
For Sending long variables, a simple SendMessage_() would do it.
If you send expliztly ro the window of the receiving app (and not to
#HWND_BROADCAST), you can simply choose you own Constant as
the Message Value. Choose something above #WM_USER, as all
message numbers below are reserved for the system, the ones above
#WM_user are free to use by apps.
You can set the lParam and wParam parameters to the VAriables, yopu wish to send.
The App, that will receave the message, should have a WindowCallback()
procedure set to receive it, (is better that catching it with the usual
message loop)
In the Callback,when receiving your message constant, you can work
with the sent values, and then return a Value with ProcedureReturn
(other than the usual #PB_ProcessPureBAsicEvents). This return
value will be the return VAlue of your SendMessage_() call in the first app.
This means, that the first app waits, until the second one has processed
the message in the WindowCallback(), and then return, so you shouldn't
do things that take long in the callback procedure.
Hmm, does sombody understand my explanation, or am i talking nonsense?
Anyway, here is another Example, of how to Send Strings between two Apps:
http://freak.purearea.net/code/
Look at: SendMessageSttring and SendMessageString2 examples.
Hope that helps...
Timo
If you send expliztly ro the window of the receiving app (and not to
#HWND_BROADCAST), you can simply choose you own Constant as
the Message Value. Choose something above #WM_USER, as all
message numbers below are reserved for the system, the ones above
#WM_user are free to use by apps.
You can set the lParam and wParam parameters to the VAriables, yopu wish to send.
The App, that will receave the message, should have a WindowCallback()
procedure set to receive it, (is better that catching it with the usual
message loop)
In the Callback,when receiving your message constant, you can work
with the sent values, and then return a Value with ProcedureReturn
(other than the usual #PB_ProcessPureBAsicEvents). This return
value will be the return VAlue of your SendMessage_() call in the first app.
This means, that the first app waits, until the second one has processed
the message in the WindowCallback(), and then return, so you shouldn't
do things that take long in the callback procedure.
Hmm, does sombody understand my explanation, or am i talking nonsense?
Anyway, here is another Example, of how to Send Strings between two Apps:
http://freak.purearea.net/code/
Look at: SendMessageSttring and SendMessageString2 examples.
Hope that helps...
Timo
quidquid Latine dictum sit altum videtur
-
cecilcheah
- Enthusiast

- Posts: 168
- Joined: Wed Jun 04, 2003 8:44 am
- Location: Switzerland
Hi
So my PB programme would send a message to this external programme, ask it to execute something and return some variable values (which can be a very long string). The problem is i do not know how to receive this variable values.
I have looked at your SendMessage examples, it works fine with 2 PB programmes, but broken down when one of them is not PB.
Any idea?
Cecil
You see the external programme is really an external independent programme that i cannot programme. I can programme PB, to send message to this alien programme.The App, that will receave the message, should have a WindowCallback()
procedure set to receive it, (is better that catching it with the usual
message loop)
So my PB programme would send a message to this external programme, ask it to execute something and return some variable values (which can be a very long string). The problem is i do not know how to receive this variable values.
I have looked at your SendMessage examples, it works fine with 2 PB programmes, but broken down when one of them is not PB.
Any idea?
Cecil
-
cecilcheah
- Enthusiast

- Posts: 168
- Joined: Wed Jun 04, 2003 8:44 am
- Location: Switzerland
-
cecilcheah
- Enthusiast

- Posts: 168
- Joined: Wed Jun 04, 2003 8:44 am
- Location: Switzerland
So the other program is not designed to exchange data with your
program, am i right?
Or course you can read the program's memory (if you have the right to),
but how would you know wher to look for your data.
Sending messages to the other program only makes sense, if the other
program knows how to handle them.
There is no standart "give me the contents of variable xyz" message.
Maybe I still don't get what you try to do.
If you tell me what program it is, and what you want to do, maybe i can
help you.
Timo
program, am i right?
Or course you can read the program's memory (if you have the right to),
but how would you know wher to look for your data.
Sending messages to the other program only makes sense, if the other
program knows how to handle them.
There is no standart "give me the contents of variable xyz" message.
Maybe I still don't get what you try to do.
If you tell me what program it is, and what you want to do, maybe i can
help you.
Timo
quidquid Latine dictum sit altum videtur
-
cecilcheah
- Enthusiast

- Posts: 168
- Joined: Wed Jun 04, 2003 8:44 am
- Location: Switzerland
Hi
OK, i try to answer everyone question as best as i can.
Anyway i can pass variables between the two?
Cecil
OK, i try to answer everyone question as best as i can.
Yes, you are right. It is just a Windows programme which i want to make a plugin to this programme with PB. The Window application is called Toolbook.So the other program is not designed to exchange data with your
program, am i right?
I have succeeded in sending messages to this programme. I am able to move a control say a button to another position. Now i want the programme to return some values back to my PB programme after receiving the message from PB.Sending messages to the other program only makes sense, if the other
program knows how to handle them.
Yes.Is this application a windows application with text and edit controls?
Some yes, some not. Like global variables will not be in a control, but in the programme.Is the data you want in these controls?
No, I use a modified send messages function to send commands which is used by this programme.Are you sending data in the form of emulated keystrokes and mouse clicks?
No, full window applicationis it a console application?
Anyway i can pass variables between the two?
Cecil
The data that is held in windows controls you can read data from. Use the following API calls:
WindowFromPoint_()
Use this to get the handle for the control.
GetWindowText_()
Once you have the handle you can get the controls text.
There is no way of accessing the programs internal variables. Just imagine the security consequences if you could!
How did you find out what messages to send the application?
I see that Toolbook has its own language, Openscript. Was the application your trying to talk to written in OpenScript?
It may be that methods of looking at OpenScripts internals exist - find a good OpenScript developers forum and ask for examples in C. Converting theses to Purebasic should be easy enough.
WindowFromPoint_()
Use this to get the handle for the control.
GetWindowText_()
Once you have the handle you can get the controls text.
There is no way of accessing the programs internal variables. Just imagine the security consequences if you could!
How did you find out what messages to send the application?
I see that Toolbook has its own language, Openscript. Was the application your trying to talk to written in OpenScript?
It may be that methods of looking at OpenScripts internals exist - find a good OpenScript developers forum and ask for examples in C. Converting theses to Purebasic should be easy enough.
-
cecilcheah
- Enthusiast

- Posts: 168
- Joined: Wed Jun 04, 2003 8:44 am
- Location: Switzerland
Hi
So looks like there is no way of doing it unless i have the internal sozurce code of toolbook itself...
Take a look at this web site:
http://www.webcbt.ch, try the Download - Utility link and see the TBK Capture i have just developed from PB and made available for free for Toolbook Developers.
Thanks
Cecil
No, i need to access more properties than this. I know how to do this already.WindowFromPoint_()
Use this to get the handle for the control.
GetWindowText_()
Once you have the handle you can get the controls text.
Openscript command, as you say.How did you find out what messages to send the application?
No, i actually try to access Toolbook stuff itself, not programme developed from Toolbook.I see that Toolbook has its own language, Openscript. Was the application your trying to talk to written in OpenScript?
I am the expert of it, or one of the experts anyway.find a good OpenScript developers
So looks like there is no way of doing it unless i have the internal sozurce code of toolbook itself...
Take a look at this web site:
http://www.webcbt.ch, try the Download - Utility link and see the TBK Capture i have just developed from PB and made available for free for Toolbook Developers.
Thanks
Cecil
> So you can't access another memory area except with regular API
> function like 'ReadProcessMemory_()'
Of course. That's why i said, if you have the right to.
OpenProcess_(), ReadProcessMemory_() etc...
cecilcheah:
Sorry, i can't help you there, i have no idea how to find the memory area
of that program where, let's say the global variables are stored.
Timo
> function like 'ReadProcessMemory_()'
Of course. That's why i said, if you have the right to.
OpenProcess_(), ReadProcessMemory_() etc...
cecilcheah:
Sorry, i can't help you there, i have no idea how to find the memory area
of that program where, let's say the global variables are stored.
Timo
quidquid Latine dictum sit altum videtur
Cecil,
The situation is more complicated.
Imagine you code the next app
This small app just do something (whatever) to a string and have it in memory.
As you see, the app was not planned to interact with an external one, so if you want to acces the MyVar$ value you have to *hack* it, is NOT easy.
AFAIK the is no any easy API that let you do this.
Some apps, like winamp, was developed having in mind a way to exchange info with external apps and then you can find a winamp API on its documentation that tell you how to do it, because as there is no 'standard' way, every app works in the way that the developers wants (many sometime could use some 'protocol' but other times uses its own).
In resume: Look at the documentation of the app that you want to interacti with, if it DOSENT describe any API to interact with, then you need to *hack* it if you want to do something more that sendkeys, etc.
For security reason (to avoid hacks) every window app uses its own RESTRICTED memory area to store values, etc.
*The opposite model is the dll, its developed to share its procedures, However you must have the documentation to use it properly.
The situation is more complicated.
Imagine you code the next app
Code: Select all
If OpenWindow(0,100,150,450,200,#PB_Window_SystemMenu,"Test")
CreateGadgetList(WindowID())
StringGadget(1,50,50,350,20,"")
ButtonGadget(2,200,100,50,25,"Test")
Repeat
EventID=WaitWindowEvent()
Select EventID
Case #PB_EventGadget
Select EventGadgetID()
Case 2
MyVar$ = ReplaceString(LCase(GetGadgetText(1)),"a","b",0)
EndSelect
EndSelect
Until EventID=#PB_EventCloseWindow
EndIf
As you see, the app was not planned to interact with an external one, so if you want to acces the MyVar$ value you have to *hack* it, is NOT easy.
AFAIK the is no any easy API that let you do this.
Some apps, like winamp, was developed having in mind a way to exchange info with external apps and then you can find a winamp API on its documentation that tell you how to do it, because as there is no 'standard' way, every app works in the way that the developers wants (many sometime could use some 'protocol' but other times uses its own).
In resume: Look at the documentation of the app that you want to interacti with, if it DOSENT describe any API to interact with, then you need to *hack* it if you want to do something more that sendkeys, etc.
For security reason (to avoid hacks) every window app uses its own RESTRICTED memory area to store values, etc.
*The opposite model is the dll, its developed to share its procedures, However you must have the documentation to use it properly.
ARGENTINA WORLD CHAMPION


