| View previous topic :: View next topic |
| Author |
Message |
Volodymyr Novikov Guest
|
Posted: Sun Aug 21, 2005 6:16 pm Post subject: Retrieving another application data |
|
|
Hello All.
I am writing an application which has to communicate with another
application by retrieving members of data structure within the application.
What I am doing basically is:
1.Define structure same way as it defined in another application.
2. Receive from another application address of the structure using socket
connection.
3. Assign received address to a pointer to the structure.
Now comes trouble: when I try to access structure member like
ptrStruct->Member
I am as expected getting an Address violation exception.
Is there any way of getting around this?
Thanks in advance and sorry if the question is too stupid.
Regards.
|
|
| Back to top |
|
 |
Michel Leunen Guest
|
Posted: Sun Aug 21, 2005 7:11 pm Post subject: Re: Retrieving another application data |
|
|
Volodymyr Novikov wrote:
| Quote: | I am writing an application which has to communicate with another
application by retrieving members of data structure within the application.
What I am doing basically is:
1.Define structure same way as it defined in another application.
2. Receive from another application address of the structure using socket
connection.
3. Assign received address to a pointer to the structure.
Now comes trouble: when I try to access structure member like
ptrStruct->Member
I am as expected getting an Address violation exception.
|
This won't work because each process is executed in its own memory
space. Instead, look at CreateFileMapping()/OpenFilemapping() or use
your socket but send the data instead of the address of the structure.
There are other ways like pipes for instance to do this job.
Michel
--
----------------------------------------
Michel Leunen
mailto: see my homepage.
C++Builder, BCC5.5.1 Web site:
http://www.leunen.com/
----------------------------------------
|
|
| Back to top |
|
 |
Duane Hebert Guest
|
Posted: Sun Aug 21, 2005 8:03 pm Post subject: Re: Retrieving another application data |
|
|
"Volodymyr Novikov" <v.novikov (AT) sympatico (DOT) ca> wrote
| Quote: | Hello All.
I am writing an application which has to communicate with another
application by retrieving members of data structure within the application.
What I am doing basically is:
1.Define structure same way as it defined in another application.
2. Receive from another application address of the structure using socket
connection.
3. Assign received address to a pointer to the structure.
Now comes trouble: when I try to access structure member like
ptrStruct->Member
|
How about sending/receiving the data from the structure and
constructing a new one on the receiving end with that data?
We usually add a ctor for the struct that takes a string that's
built from socket data. This way there's a local copy (adress
space wise) of the structure.
|
|
| Back to top |
|
 |
JD Guest
|
Posted: Sun Aug 21, 2005 10:18 pm Post subject: Re: Retrieving another application data |
|
|
"Volodymyr Novikov" <v.novikov (AT) sympatico (DOT) ca> wrote:
| Quote: |
[...] What I am doing basically is: [...]
|
The AV is thrown because one application is attempting to
access memory that is owned by another application. Use
WM_COPYDATA instead.
~ JD
|
|
| Back to top |
|
 |
Volodymyr Novikov Guest
|
Posted: Sun Aug 21, 2005 11:16 pm Post subject: Re: Retrieving another application data |
|
|
Yes, I considered this possibility and disregarded it as too slow (data send
thru socket takes ~100ms, which is too slow for my case). Would be more than
OK in 99% of cases though.
Thanks anyway.
"Duane Hebert" <spoo (AT) flarn2 (DOT) com> wrote
| Quote: |
"Volodymyr Novikov" <v.novikov (AT) sympatico (DOT) ca> wrote in message
news:4308c504 (AT) newsgroups (DOT) borland.com...
Hello All.
I am writing an application which has to communicate with another
application by retrieving members of data structure within the
application.
What I am doing basically is:
1.Define structure same way as it defined in another application.
2. Receive from another application address of the structure using
socket
connection.
3. Assign received address to a pointer to the structure.
Now comes trouble: when I try to access structure member like
ptrStruct->Member
How about sending/receiving the data from the structure and
constructing a new one on the receiving end with that data?
We usually add a ctor for the struct that takes a string that's
built from socket data. This way there's a local copy (adress
space wise) of the structure.
|
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Mon Aug 22, 2005 5:14 pm Post subject: Re: Retrieving another application data |
|
|
"Volodymyr Novikov" <v.novikov (AT) sympatico (DOT) ca> wrote
| Quote: | 2. Receive from another application address of the structure
using socket connection.
3. Assign received address to a pointer to the structure.
|
You cannot do that. Each application has its own memory address space that
is separate from every other application. A memory address in one
application WILL NOT be a valid memory address in another application.
To do what you are asking for, you need to send the actual data members that
are contained inside the structure. You cannot send just a pointer to the
structure itself. On the receiving end, it reads the data and uses it to
populate a local instance of the structure.
| Quote: | Now comes trouble: when I try to access structure member
like ptrStruct->Member
I am as expected getting an Address violation exception.
|
Of course, because what you are trying to do is illegal. Applications
cannot access each other's address space.
Gambit
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Mon Aug 22, 2005 5:23 pm Post subject: Re: Retrieving another application data |
|
|
"Volodymyr Novikov" <v.novikov (AT) sympatico (DOT) ca> wrote
| Quote: | Yes, I considered this possibility and disregarded it as too slow
(data send thru socket takes ~100ms, which is too slow for my case).
|
Then your requirement is too restrictive, because sending the actual data is
the only way to send anything over a socket. Also, you are probably not
using the socket correctly in the first place, because you should be able to
send data much faster than 100ms, especially if the two applications are on
the same machine. But you did not show any of your actual code, so there is
no way to know if you are managing the socket correctly. Even so, if the
socket is still too slow for you, then using a socket is not the best choice
for your application in the first place.
Gambit
|
|
| Back to top |
|
 |
Volodymyr Novikov Guest
|
Posted: Mon Aug 22, 2005 11:46 pm Post subject: Re: Retrieving another application data |
|
|
"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote
| Quote: |
"Volodymyr Novikov" <v.novikov (AT) sympatico (DOT) ca> wrote in message
news:43090b59$1 (AT) newsgroups (DOT) borland.com...
Yes, I considered this possibility and disregarded it as too slow
(data send thru socket takes ~100ms, which is too slow for my case).
Then your requirement is too restrictive, because sending the actual data
is
the only way to send anything over a socket. Also, you are probably not
using the socket correctly in the first place, because you should be able
to
send data much faster than 100ms, especially if the two applications are
on
the same machine. But you did not show any of your actual code, so there
is
no way to know if you are managing the socket correctly. Even so, if the
socket is still too slow for you, then using a socket is not the best
choice
for your application in the first place.
Gambit
|
This is a piece of testcode to mesure time from request to reply. Time delay
includes also reply callback procedure within another application, which is
very simple hence may be neglected. TclientSocket is used on both sides:
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
t1=timeGetTime();
CSocket1->Socket->SendText(Edit1->Text+"rn");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::CSocket1Read(TObject *Sender,
TCustomWinSocket *Socket)
{
ch=Socket->ReceiveText();
lastline=ch;
Bar1->Panels->Items[1]->Text=IntToStr(timeGetTime()-t1);
Bar1->Panels->Items[0]->Text=ch;
//---------------------------------------------------------------------------
Propagation time in my case lies within 40-150ms.
Thanks,
Vladimir.
|
|
| Back to top |
|
 |
Duane Hebert Guest
|
Posted: Mon Aug 22, 2005 11:56 pm Post subject: Re: Retrieving another application data |
|
|
"Volodymyr Novikov" <v.novikov (AT) sympatico (DOT) ca> wrote
| Quote: | This is a piece of testcode to mesure time from request to reply. Time delay
includes also reply callback procedure within another application, which is
very simple hence may be neglected. TclientSocket is used on both sides:
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
t1=timeGetTime();
CSocket1->Socket->SendText(Edit1->Text+"rn");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::CSocket1Read(TObject *Sender,
TCustomWinSocket *Socket)
{
ch=Socket->ReceiveText();
lastline=ch;
Bar1->Panels->Items[1]->Text=IntToStr(timeGetTime()-t1);
Bar1->Panels->Items[0]->Text=ch;
//---------------------------------------------------------------------------
Propagation time in my case lies within 40-150ms.
Thanks,
Vladimir.
|
I assume that CSocket1Read() is an event. If this is so, you're
timing is based on when the event loop updates more than
the time it takes to send the data. You may want to try
polling for data directly. You can normally send quite a bit of
data through a socket in 150ms.
If this is a strictly windows application, you may also want
to look at some of the other ideas suggested in this thread.
|
|
| Back to top |
|
 |
Volodymyr Novikov Guest
|
Posted: Mon Aug 22, 2005 11:58 pm Post subject: Re: Retrieving another application data |
|
|
"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote
| Quote: |
"Volodymyr Novikov" <v.novikov (AT) sympatico (DOT) ca> wrote in message
news:4308c504 (AT) newsgroups (DOT) borland.com...
2. Receive from another application address of the structure
using socket connection.
3. Assign received address to a pointer to the structure.
You cannot do that. Each application has its own memory address space
that
is separate from every other application. A memory address in one
application WILL NOT be a valid memory address in another application.
To do what you are asking for, you need to send the actual data members
that
are contained inside the structure. You cannot send just a pointer to the
structure itself. On the receiving end, it reads the data and uses it to
populate a local instance of the structure.
Now comes trouble: when I try to access structure member
like ptrStruct->Member
I am as expected getting an Address violation exception.
Of course, because what you are trying to do is illegal. Applications
cannot access each other's address space.
Gambit
|
I gave up socket connection and now using WM_COPYDATA Message which works OK
for me.
....And still where must be a way of direct accessing another's application
data which is of course illegal from the viewpoint of Windows i.e hacker
stuff mostly.
Thanks everybody fir help.
Regards, Vladimir.
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Tue Aug 23, 2005 6:52 am Post subject: Re: Retrieving another application data |
|
|
"Volodymyr Novikov" <v.novikov (AT) sympatico (DOT) ca> wrote
| Quote: | This is a piece of testcode to mesure time from request to reply.
|
That code is going to be slow because you are using the socket in
non-blocking mode, which means the speed of the processing is directly
related to the speed in which the application can process messages from the
main message queue. If you change to using a blocking socket instead, and
put in it a worker thread, you are likely to see a bit of a speed increase,
both in GUI responsiveness and in data processing.
| Quote: | TclientSocket is used on both sides:
|
Two client sockets cannot communicate with each other. One of the
applications has to be using a server socket that the client socket then
connects to.
Gambit
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Tue Aug 23, 2005 6:55 am Post subject: Re: Retrieving another application data |
|
|
"Volodymyr Novikov" <v.novikov (AT) sympatico (DOT) ca> wrote
| Quote: | ...And still where must be a way of direct accessing
another's application data
|
The OS strictly prohibits that. That is why each application has its own
address space to begin with - specifcally so that application cannot access
each other's memory directly. Also so that if one application crashes, it
doesn't (usually) take down other applications with it.
The only application that can access another application's memory is a
debugger, for obvious reasons.
Gambit
|
|
| Back to top |
|
 |
Alan Bellingham Guest
|
Posted: Tue Aug 23, 2005 9:51 am Post subject: Re: Retrieving another application data |
|
|
"Volodymyr Novikov" <v.novikov (AT) sympatico (DOT) ca> wrote:
| Quote: | ...And still where must be a way of direct accessing another's application
data which is of course illegal from the viewpoint of Windows i.e hacker
stuff mostly.
|
There are ways. They involve rewriting chunks of the operating system.
Alan Bellingham
--
ACCU Conference 2006 - 19-22 April, Randolph Hotel, Oxford, UK
|
|
| Back to top |
|
 |
|