View previous topic :: View next topic |
Author |
Message |
bornsoft Contributor
![Contributor Contributor](ranks/star1b.gif)
Joined: 19 Feb 2009 Posts: 113 Location: Germany
|
Posted: Fri Feb 26, 2010 2:15 pm Post subject: Problems reading from a pipe using API |
|
|
Hello, i hope one of you can help me ...
I try to communicate between two apps using a pipe and found a strange behaviour.
The code below works perfect if i run it one after another within one script. I get my string from the beginning back. But if I split it into a write-to-pipe and a read-from-pipe part and run them in two different instances of the VDS-IDE the reading part doesn't work.
I copy the reading part and open it in a second IDE. Then I first run the writing part until the breakpoint is reached.
Then i un-rem in the second window %R an %L and give them the values i see in the debugger of IDE 1. Then i single step thru the reading part in IDE 2. It is the correct ReadHandle and everything is much the same, but it doesn't work.
Please have a look at it, I think there must be something I overlook.
Code: |
# -- Create pipe, get ReadHandle and WriteHandle, than write to the pipe and
# close the WriteHandle.
# My initial string
%S = "Hallo VDS-World!"@chr(0)
# Length
%L = @len(%S)
# ReadHandle
%R = @binary(DWORD,0)
# WriteHandle
%W = @binary(DWORD,0)
loadlib kernel32
# Create the pipe
%x = @LIB(KERNEL32,CreatePipe,BOOL:,INT:@addr("%R"),INT:@addr("%W"),INT:NULL,INT:%L)
%R = @val(%R)
%W = @val(%W)
# Write Buffer
%B = @binary(DWORD,0)
# Write to pipe
%x = @LIB(KERNEL32,WriteFile,BOOL:,INT:%W,INT:@addr("%S"),%L,INT:@addr("%B"),INT:NULL)
%B = @val(%B)
# Close WriteHandle
%x = @LIB(KERNEL32,CloseHandle,BOOL:,INT:%W)
freelib kernel32
# -- BreakPoint here -- copy the part beneath to another IDE-instance, un-REM the
# variables %R and %L and assign them the current values for
# ReadHandle and Length.
# -- Read from the pipe starts here --
# %R =
# %L =
# Get string here in
%S = @fill(%L,,Z)
# Buffer for sent bytes
%B = @binary(DWORD,0)
loadlib kernel32
# Read from the pipe
%x = @LIB(KERNEL32,ReadFile,BOOL:,INT:%R,INT:@addr("%S"),INT:%L,INT:@addr("%B"),INT:NULL )
%B = @val(%B)
# Close ReadHandle, the pipe is closed automatically
%x = @LIB(KERNEL32,CloseHandle,BOOL:,INT:%R)
freelib kernel32
info My string is @chr(34)%S@chr(34)@tab()
exit
|
|
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
SnarlingSheep Professional Member
![Professional Member Professional Member](ranks/star3b.gif)
![](images/avatars/42e3f99d3e1b5e6a40aed.gif)
Joined: 13 Mar 2001 Posts: 759 Location: Michigan
|
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
bornsoft Contributor
![Contributor Contributor](ranks/star1b.gif)
Joined: 19 Feb 2009 Posts: 113 Location: Germany
|
Posted: Sat Feb 27, 2010 10:09 am Post subject: |
|
|
I came across atoms, it's a good way to communicate but it is limited to 255 bytes. In most cases this should be enough but i decided not to use it for that reason. I also tryed RtlMoveMemory but this didn't work correct, sometimes there were bytes overwritten. |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
vdsalchemist Admin Team
![](images/avatars/172827908242fa5a2baae92.gif)
Joined: 23 Oct 2001 Posts: 1448 Location: Florida, USA
|
Posted: Fri Mar 05, 2010 2:48 am Post subject: |
|
|
The issue is not that your code is wrong. The issue is that you are violating process security by allocating memory in the heap of one process and sending that memory address to another process. You should use something like a file mapping and this usually involves a DLL as a gateway. Might I suggest using one of many of the data sharing VDS extensions available from the main page http://www.vdsworld.com
It may be easier than reinventing the wheel. _________________ Home of
Give VDS a new purpose!
![](http://www.dragonsphere.net/images/dslogotext-h32.gif) |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
vdsalchemist Admin Team
![](images/avatars/172827908242fa5a2baae92.gif)
Joined: 23 Oct 2001 Posts: 1448 Location: Florida, USA
|
Posted: Fri Mar 05, 2010 2:55 am Post subject: |
|
|
Here is another thought Why don't you just use DDE? It is built into VDS and works just as good as Pipe's, File mappings, and Atoms. _________________ Home of
Give VDS a new purpose!
![](http://www.dragonsphere.net/images/dslogotext-h32.gif) |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|