forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Problems reading from a pipe using API

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Advanced Help for VDS 5 & Up
View previous topic :: View next topic  
Author Message
bornsoft
Contributor
Contributor


Joined: 19 Feb 2009
Posts: 113
Location: Germany

PostPosted: Fri Feb 26, 2010 2:15 pm    Post subject: Problems reading from a pipe using API Reply with quote

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
View user's profile Send private message Visit poster's website
SnarlingSheep
Professional Member
Professional Member


Joined: 13 Mar 2001
Posts: 759
Location: Michigan

PostPosted: Fri Feb 26, 2010 5:25 pm    Post subject: Reply with quote

Try this code I just posted for what I think is the easiest way to communicate between your VDS apps:
http://www.vdsworld.com/forum/viewtopic.php?p=35444

_________________
-Sheep
My pockets hurt...
Back to top
View user's profile Send private message Send e-mail
bornsoft
Contributor
Contributor


Joined: 19 Feb 2009
Posts: 113
Location: Germany

PostPosted: Sat Feb 27, 2010 10:09 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
vdsalchemist
Admin Team


Joined: 23 Oct 2001
Posts: 1448
Location: Florida, USA

PostPosted: Fri Mar 05, 2010 2:48 am    Post subject: Reply with quote

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!
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
vdsalchemist
Admin Team


Joined: 23 Oct 2001
Posts: 1448
Location: Florida, USA

PostPosted: Fri Mar 05, 2010 2:55 am    Post subject: Reply with quote

Here is another thought Idea 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!
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Advanced Help for VDS 5 & Up All times are GMT
Page 1 of 1

 
Jump to:  
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




Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group