passing parameters between 2 exe

passing parameters between 2 exe

Postby Richard Chidiak » Thu Apr 25, 2013 7:52 pm

Hello

How can we pass a parameter between 2 exe and how the second will retreive it ?

i know shellexecute(....) can pass parameter

in program1.exe shellexecute(,"open""program2.exe",param)

is there another way to do it and how to retreive the param in program2

Thanks for help,

Richard
http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
User avatar
Richard Chidiak
 
Posts: 946
Joined: Thu Oct 06, 2005 7:05 pm
Location: France

Re: passing parameters between 2 exe

Postby Enrico Maria Giordano » Thu Apr 25, 2013 8:02 pm

You can use a file to pass and receive parameters.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8315
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: passing parameters between 2 exe

Postby Enrico Maria Giordano » Thu Apr 25, 2013 8:03 pm

Richard Chidiak wrote:how to retreive the param in program2


Code: Select all  Expand view
FUNCTION MAIN( cParam1, cParam2, etc. )


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8315
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: passing parameters between 2 exe

Postby Richard Chidiak » Thu Apr 25, 2013 8:05 pm

Exactly what i am looking for

Thank you Enrico

Richard
http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
User avatar
Richard Chidiak
 
Posts: 946
Joined: Thu Oct 06, 2005 7:05 pm
Location: France

Re: passing parameters between 2 exe

Postby Antonio Linares » Thu Apr 25, 2013 8:37 pm

According to the Windows API this is the way to do it (of course other systems work fine as well). This way is to send data to an already running app:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms649011(v=vs.85).aspx

A working example:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms649009(v=vs.85).aspx
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: passing parameters between 2 exe

Postby devtuxtla » Fri Apr 26, 2013 1:06 am

Hi Antonio.

For those who do not know C + +

It is possible to have an example of this code to operate in xHarbour and Harbour?

regards
Visite Chiapas, el paraiso de México.
devtuxtla
 
Posts: 392
Joined: Tue Jul 29, 2008 1:55 pm

Re: passing parameters between 2 exe

Postby nageswaragunupudi » Fri Apr 26, 2013 3:42 am

Here are two sample programs.
wndsend.prg
wndget.prg

Code: Select all  Expand view
// wndsend.prg

#include "fivewin.ch"
#include "xbrowse.ch"

REQUEST DBFCDX

//----------------------------------------------------------------------------//

function Main()

   local oWnd, oBar, oBrw

   USE CUSTOMER NEW VIA "DBFCDX"

   DEFINE WINDOW oWnd TITLE "SendWnd"
   DEFINE BUTTONBAR oBar OF oWnd SIZE 100,32 2007
   DEFINE BUTTON OF oBar PROMPT "SendMsg" ACTION SendData()
   SET MESSAGE OF oWnd TO '' 2007

   @ 0,0 XBROWSE oBrw OF oWnd ALIAS "CUSTOMER" ;
      AUTOCOLS CELL LINES NOBORDER

   oBrw:CreateFromCode()
   oWnd:oClient   := oBrw

   ACTIVATE WINDOW oWnd
   CLOSE DATA

return 0

//----------------------------------------------------------------------------//

static function SendData()

   local hDstWnd  := FindWindow( "TCDWnd", "GetWnd" )

   if Empty( hDstWnd )
      ? "window not found"
   else
      SendDataToApp( hDstWnd, 1, ;
         FW_ValToExp( { CUSTOMER->FIRST, CUSTOMER->LAST, CUSTOMER->CITY } ), ;
         WndMain():hWnd )
   endif

return nil

//----------------------------------------------------------------------------//

//----------------------------------------------------------------------------//

#pragma BEGINDUMP

#include <windows.h>
#include <hbapi.h>

HB_FUNC (SENDDATATOAPP) // ( hDestWnd, nMsgID, cData, hFromWnd )
{
   COPYDATASTRUCT cds;

   cds.dwData     = hb_parnl( 2 );
   cds.cbData     = hb_parclen( 3 );
   cds.lpData     = (PVOID) hb_parcx( 3 );

   SendMessage( (HWND) hb_parnl( 1 ), WM_COPYDATA, (WPARAM) (HWND) hb_parnl( 4 ), (LPARAM) (LPVOID) &cds );
   hb_ret();
}

HB_FUNC (PARSECOPYDATA)
{
   PCOPYDATASTRUCT pCDS;

   pCDS           = (PCOPYDATASTRUCT) hb_parnl( 1 );
   hb_stornl( pCDS->dwData, 2 );
   hb_retclen( pCDS->lpData, pCDS->cbData );

}

#pragma ENDDUMP

//============================================================================//
 


wndget.prg:
Code: Select all  Expand view
// wndget.prg

#include "fivewin.ch"
#include "xbrowse.ch"

REQUEST DBFCDX

//----------------------------------------------------------------------------//

function Main()

   local oWnd, oBar, oBrw

   oWnd  := TCDWnd():New( nil, nil, nil, nil, "GetWnd" )
   DEFINE BUTTONBAR oBar OF oWnd SIZE 100,32 2007
   SET MESSAGE OF oWnd TO ''

   oWnd:bOnGetData   := { |oWnd, oFrom, nID, cData| ;
      OnGetData( oWnd, oFrom, nID, cData, oBrw ) }

   @ 0,0 XBROWSE oBrw OF oWnd DATASOURCE {} ;
      COLUMNS 1, 2, 3 ;
      HEADERS "First", "Last", "City" ;
      COLSIZES 80, 80, 80 ;
      CELL LINES NOBORDER

   oBrw:CreateFromCode()
   oWnd:oClient   := oBrw

   ACTIVATE WINDOW oWnd
   CLOSE DATA

return 0

//----------------------------------------------------------------------------//

static function OnGetData( oWnd, oFrom, nMsgID, cData, oBrw )

   AAdd( oBrw:aArrayData, &cData )
   oBrw:GoBottom()
   oBrw:Refresh()
   oBrw:SetFocus()

return nil

//----------------------------------------------------------------------------//

//============================================================================//

#define WM_COPYDATA                     0x004A

CLASS TCDWnd FROM TWindow STATIC

   DATA bOnGetData

   CLASSDATA lRegistered AS LOGICAL

   METHOD HandleEvent( nMsg, nWParam, nLParam )

ENDCLASS

//----------------------------------------------------------------------------//

METHOD HandleEvent( nMsg, nWParam, nLParam ) CLASS TCDWnd

   local nDataID := 0, cData

   if nMsg == WM_COPYDATA
      if ::bOnGetData != nil
         cData    := ParseCopyData( nLParam, @nDataID )
         Eval( ::bOnGetData, Self, nWParam, nDataID, cData )
         return 0
      endif
   endif

return ::Super:HandleEvent( nMsg, nWParam, nLParam )

//----------------------------------------------------------------------------//

//----------------------------------------------------------------------------//

#pragma BEGINDUMP

#include <windows.h>
#include <hbapi.h>

HB_FUNC (SENDDATATOAPP) // ( hDestWnd, nMsgID, cData, hFromWnd )
{
   COPYDATASTRUCT cds;

   cds.dwData     = hb_parnl( 2 );
   cds.cbData     = hb_parclen( 3 );
   cds.lpData     = (PVOID) hb_parcx( 3 );

   SendMessage( (HWND) hb_parnl( 1 ), WM_COPYDATA, (WPARAM) (HWND) hb_parnl( 4 ), (LPARAM) (LPVOID) &cds );
   hb_ret();
}

HB_FUNC (PARSECOPYDATA)
{
   PCOPYDATASTRUCT pCDS;

   pCDS           = (PCOPYDATASTRUCT) hb_parnl( 1 );
   hb_stornl( pCDS->dwData, 2 );
   hb_retclen( pCDS->lpData, pCDS->cbData );

}

#pragma ENDDUMP

//============================================================================//
 


Independently compile and build the two exes wndsend.exe and wndget.exe, either in Harbour or xHarbour.

wndsend.prg opens and shows browse of customer.dbf in fwh\samples folder. You may need the exe files located in fwh\samples folder or have the customer.dbf in the same folder where the wndsend.exe resides.

Launch both programs and move the windows so that you can see both windows without overlapping each other.

wndget.exe shows browse of an empty array with three columns.

wndsend.exe shows browse of customer.dbf. Move to any row of the browse and click "SendMsg" button on the buttonbar.

Now this program sends an array of CUSTOMER->FIRST, CUSTOMER->LAST, CUSTOMER-CITY to WndGet.Exe through WM_COPYDATA message.
WndGet.exe responds to WM_COPYDATA message and retrieves the data, appends to the array and displays the data in the browse.

Keep moving to different rows in the customer browse of WndSend.Exe and press "SendMsg" button. The information of the row is received by WndGet.Exe and shown in its array browse.

Notes:
I have used SendMessage() function to send the messages. Those who are aware the difference between SendMessage() and PostMessage() may be tempted to use PostMessage(), but that does not work here.

The disadvantage of SendMessage() is that the sending program waits till the responding application completes processing the message ( or ignores ). In the case of our example, till the HandleEvent method returns 0.

Therefore the responding program should retrieve and store the message and signal handling of the event fast.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10248
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: passing parameters between 2 exe

Postby cnavarro » Fri Apr 26, 2013 7:36 am

Mr Rao
Thanks for such a detailed explanation
Regards
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6500
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: passing parameters between 2 exe

Postby devtuxtla » Fri Apr 26, 2013 7:30 pm

Hello nages

Thanks for the example

I'll try

Thanks again
Visite Chiapas, el paraiso de México.
devtuxtla
 
Posts: 392
Joined: Tue Jul 29, 2008 1:55 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 103 guests