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 


Using Global Atoms to Send/Receive between 2 programs

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Advanced VDS 5 Source Code
View previous topic :: View next topic  
Author Message
SnarlingSheep
Professional Member
Professional Member


Joined: 13 Mar 2001
Posts: 759
Location: Michigan

PostPosted: Fri Feb 26, 2010 5:24 pm    Post subject: Using Global Atoms to Send/Receive between 2 programs Reply with quote

This example should help those wanting to communicate between 2 of their VDS Apps.
It should work best if you compile and run 2 instances of the program.
It will automatically choose to be the sending program if only one is open, and the receiving program once the second is opened.
It will create and send the atom identifier to itself if only one instance is open.
Code:

  #define function,ReadAtom
  #define function,WriteAtom
  #define function,DeleteAtom
  #define function,SendAtom
  option MSGEVENT,10667,ATOMMSG,HANDLED
 
  REM Find out if this is the SEND program or RECEIVE program
  if @winexists(#AtomSendExample)
    %%Class = AtomReceiveExample
  else
    %%Class = AtomSendExample
  end
 
  DIALOG CREATE,%%Class,-1,0,240,111,CLASS %%Class
  DIALOG ADD,EDIT,EDIT1,25,31,180,19,Enter Text to Send
  DIALOG ADD,BUTTON,BUTTON1,56,85,64,24,
  DIALOG SHOW 
  loadlib kernel32.dll
  loadlib user32.dll
 
:evloop
  wait event
  goto @event()
:BUTTON1BUTTON
  REM Create the Atom and send its ID to the Receiver Program if it exists.
  %%atomID = @WriteAtom(@wintext(~EDIT1))
  %%atomRETURN = @SendAtom(%%atomID)
  goto evloop
:ATOMMSG
  info @ReadAtom(@MSGPARAMS(L))
  goto evloop
:Close
  freelib kernel32.dll
  freelib user32.dll
  exit
:ReadAtom
  REM Read the text stored at Atom ID and return it
  REM %b for buffer, 255 bytes is the maximum length
  %b = @fill(255)
  %%atomReturn = @lib(kernel32.dll,GlobalGetAtomNameA,INT:,INT:%1,@addr("%b"),@len(%b))
  %%atomReturn = @DeleteAtom(%1)
  exit %b
:WriteAtom
  REM Creates the atom and returns the Atom ID
  exit @lib(kernel32,GlobalAddAtomA,INT:,STR:%1)
:DeleteAtom
  REM Deletes the atom at Atom ID, always returns 0
  exit @lib(kernel32,GlobalDeleteAtom,INT:,INT:%1)
:SendAtom
  %%atomHWND = @winexists(#AtomReceiveExample)
  if %%atomHWND
    %%atomHWND = @strdel(%%atomHWND,1,1)
  else
    REM If the Receive window isn't open, send the atom to yourself just to test.
    %%atomHWND = @strdel(@winexists(#AtomSendExample),1,1)
  end
  exit @lib(user32,PostMessageA,INT:,INT:%%atomHWND,INT:10667,0,%1)

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


Joined: 09 Aug 2007
Posts: 79

PostPosted: Wed Oct 27, 2010 1:12 pm    Post subject: Reply with quote

SnarlingSheep,

I not sure if I'm doing anything wrong but I dont beleive this works for me.

I'm running Vista
Compiled as vds 5 or vds 6 exe. does not matter.

When I click button1 it just gives me a info box saying the message that was already in edit1. I dont see any atom info.

Also both the %%atomID and %%atomRETURN returns the same atom number for either atomexaple exe.
Back to top
View user's profile Send private message
SnarlingSheep
Professional Member
Professional Member


Joined: 13 Mar 2001
Posts: 759
Location: Michigan

PostPosted: Wed Oct 27, 2010 6:30 pm    Post subject: Reply with quote

If you look, the info box isn't getting the text from the edit box, but rather storing what is in the edit box in an atom and then reading it from the atom.
Or if there are 2 instances open, the 1st stores the text and the 2nd reads it.

Both programs would need to have the same atom ID info so they can share the data in the atom.
It gives you the ability to store and read data between 2 of your programs without having to use a file or the registry.

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


Joined: 09 Aug 2002
Posts: 101
Location: Lewes, U.K.

PostPosted: Fri Nov 19, 2010 2:28 pm    Post subject: Reply with quote

SnarlingSheep,

I used your script to create a library of functions I use when ever I need
to pass data between apps.
Code:

#define function,writeAtom,readAtom,deleteAtom,sendAtom,receiveAtoms

rem ***********************************************************
rem * FUNCTION:
REM * @writeAtom(string)
REM *
REM * DATE:
REM * 181110A
REM *
rem * DSCRPTN:
REM * Creates an atom and returns the Atom ID
rem *
REM * ARGUMENTS:
rem * String
rem *
REM * RETURNS:
REM * Atom ID OR null for failure
rem ***********************************************************
:writeAtom
    %a =
    loadlib kernel32.dll
    REM Creates the atom and returns the Atom ID
    %a = @lib(kernel32,GlobalAddAtomA,INT:,STR:%1)
    freelib kernel32.dll
    exit %a

rem ***********************************************************
rem * FUNCTION:
REM * @readAtom(Atom ID)
REM *
REM * DATE:
REM * 181110A
REM *
rem * DSCRPTN:
REM * Read the text stored at Atom ID and return it
rem *
REM * ARGUMENTS:
rem * Atom ID
rem *
REM * RETURNS:
REM * String OR Null for failure
rem ***********************************************************
:readAtom
    %b =
    loadlib kernel32.dll
    REM Read the text stored at Atom ID and return it
    REM %b for buffer, 255 bytes is the maximum length
    %b = @fill(255)
    %%atomReturn = @lib(kernel32.dll,GlobalGetAtomNameA,INT:,INT:%1,@addr("%b"),@len(%b))
    if @zero(%%atomReturn)
        %b =
    end
    rem %%atomReturn = @DeleteAtom(%1)
    freelib kernel32.dll
    exit %b

rem ***********************************************************
rem * FUNCTION:
REM * @deleteAtom(Atom ID)
REM *
REM * DATE:
REM * 181110A
REM *
rem * DSCRPTN:
REM * Deletes the atom at Atom ID
rem *
REM * ARGUMENTS:
rem * Atom ID
rem *
REM * RETURNS:
REM * Always returns 0
rem ***********************************************************
:deleteAtom
    loadlib kernel32.dll
    REM Deletes the atom at Atom ID, always returns 0
    %a = @lib(kernel32,GlobalDeleteAtom,INT:,INT:%1)
    freelib kernel32.dll
    exit %a

rem ***********************************************************
rem * FUNCTION:
REM * @sendAtom(main target window title,Atom ID)
REM *
REM * DATE:
REM * 181110A
REM *
rem * DSCRPTN:
REM * Send an atom ID to a window using message No.31399($7AA7)
rem *
REM * ARGUMENTS:
rem * Target Windows Title, Atom ID
rem *
REM * RETURNS:
REM * Nozero for success OR Zero for failure
rem ***********************************************************
:sendAtom
    rem main target window title
    %h = @winexists(%1)
    if %h
        %h = @strdel(%h,1,1)
    else
        exit 0
    end
    if @null(%2)@not(@numeric(%2))
        exit 0
    end
    loadlib user32.dll
    %a = @lib(user32,PostMessageA,INT:,INT:%h,INT:31399,0,%2)
    freelib user32.dll
    exit %a

rem ***********************************************************
rem * FUNCTION:
REM * @receiveAtoms()
REM *
REM * DATE:
REM * 181110A
REM *
rem * DSCRPTN:
REM * Creates an event ATOMMSG to receive atoms
rem * Use message number 31399($7AA7) to send data
rem *
REM * ARGUMENTS:
rem * None
rem *
REM * RETURNS:
REM * Always returns 1
rem ***********************************************************
:receiveAtoms
    option MSGEVENT,31399,ATOMMSG,HANDLED
    exit 1


All the best

David Monckton
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Advanced VDS 5 Source Code 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