DDE Client.

 

When ScriptEZ.API based script file is running, an identification area is appended

to the system menu of the console windows as following:

 

 

'//////////////////////////////////////////////////////////////////////////////

' Author: SY

' Demo ScriptEZ.API based application which uses facilities from RAD API:

' . Dynamic Data Exchange (DDE) usage

' . Thread Pool usage

' . Echo() method usage which displays always messages into a console window

'   instead of WScript.Echo() with 2 behaviours for cscript.exe or wscript.exe

' . ScriptEZ.API Remoting Control Interface usage by NPTelnet.exe program

'   (Connect to ScriptEZ.API process with <processid (PID)> as connection name)

'

' Purpose: Using DDE protocol to ask 5 times per second for squence numbers to

'          a DDE Server (aka Rldrmon.exe)  which is connected to RLoader.exe

'//////////////////////////////////////////////////////////////////////////////

const SCRIPTEZ_API = "ScriptEZ.API" ' Component name

 

Dim WshShell

Dim ScriptEZ

Dim StartTime

Dim onExit

Dim hDde

Dim hThreadPool

' start the script

'////////////////

'On Error Resume Next

Main()

 

' Main Subroutine

'////////////////

Sub Main()

 

  onExit       = 0

  StartTime    = Now()

  Set WshShell = WScript.CreateObject("WScript.Shell")

 

  ' instantiate component object with callback interface

  Set ScriptEZ = WScript.CreateObject(SCRIPTEZ_API,"ScriptEZ_")

  'ScriptEZ.SetCPUCoreAffinity "0"

 

  ' Register App for receiving AppEvent(s) with onAppEvent(EventID)

  ScriptEZ.AppRegister

 

  hDde = ScriptEZ.StartConnectionToDDEServer("dde_remotelock@local","lock@local")

  ' retry to start DDE server (rldrmon.exe), if firt failure

  If hDde <= 0 Then

   WshShell.Run "rldrmon.exe /autoconnect:local",6

   WScript.Sleep 4000

   hDde = ScriptEZ.StartConnectionToDDEServer("dde_remotelock@local","lock@local")

  End If

  If hDde <= 0 Then

   ScriptEZ.AppUnregister

   Set ScriptEZ = Nothing

   Set WshShell = Nothing

   Exit Sub

  End If

 

  ' Hide console window if 0

  ScriptEZ.ShowConsoleWindow 1

 

  ' creating thread pool with 1 thread for polling info

  hThreadPool = ScriptEZ.CreateTaskQueueObject(1)

  r = ScriptEZ.AddTask( hThreadPool, hDde )   

 

  ScriptEZ.SetConsoleTitle CStr(StartTime) + " - DDE Transactions Demo"

 

  ' block until AppEventID = 3 is received

   Do Until onExit = 3

       WScript.Sleep 500

   Loop

    

  ScriptEZ.AppUnregister

  WScript.Sleep 4000

  If hDde > 0 Then ScriptEZ.ReleaseConnectionFromDDEServer hDde

  Set ScriptEZ = Nothing

  Set WshShell = Nothing

 

End Sub

 

' Callbacks for App Events notification and fetching help text

'/////////////////////////////////////////////////////////////

Sub ScriptEZ_onAppEvent(EventID)

 

 If EventID = 3 Then onExit = EventID

  

End Sub

 

Function ScriptEZ_AppEventHelp()

 

 ScriptEZ_AppEventHelp = CStr("AppEventID = 3 to exit")

 

End Function

 

 

' Callback for thread pool object (TaskQueueObject)

'//////////////////////////////////////////////////

Function ScriptEZ_onRun( localStorage )

 

  Dim seqnum

 

  WScript.Sleep 200

  If hDde > 0 Then

     seqnum = ScriptEZ.GetDataFromDDEServer(hDde,"getsequencenumber[incrementing]")

     If Len(seqnum) > 0 Then

      ScriptEZ.Echo ". My Sequence Number:" + CStr(seqnum)

      ScriptEZ.FreeBSTR seqnum

     Else

      ScriptEZ.Echo CStr(ScriptEZ.GetDdemlErrorNumber(hDde))

     End If

  End If

 

  If onExit = 3 Then

   ScriptEZ_onRun = CLng(0) ' stop this task

  Else

   ScriptEZ_onRun = CLng(1) ' run again this task

  End If

 

End Function