sharing variables between scripts with dynawrap case study #3

Tech-Archive recommends: Speed Up your PC by fixing your registry



an old problem revisited...
two scripts:
server.vbs which set shared string and client.vbs which get shared
string
enjoy

server.vbs:
Option Explicit
Const INVALID_HANDLE_VALUE=-1
Const PAGE_READWRITE=4
Const FILE_MAP_WRITE=2

Function GetBSTRPtr(ByRef sData)
Dim pSource,pDest
pSource=oApi.lstrcat(sData,"")
pDest=oApi.lstrcat(GetBSTRPtr,"")
GetBSTRPtr=CLng(0)
oApi.RtlMoveMemory pDest+8,pSource+8,4
End Function

Sub SetShared(ByRef sVar)
oApi.RtlMoveMemory lMapView,GetBSTRPtr(sVar),LenB(sVar)
End Sub

Dim oApi,hFile,sSharedSpace,lMapView
Dim sTest
sSharedSpace="ACME"

Set oApi=CreateObject("DynamicWrapper")
oApi.Register
"kernel32.dll","CreateFileMappingA","f=s","i=hlllls","r=h"
oApi.Register "kernel32.dll","MapViewOfFile","f=s","i=hllll","r=l"
oApi.Register "kernel32.dll","UnmapViewOfFile","f=s","i=l","r=l"
oApi.Register "kernel32.dll","CloseHandle","f=s","i=h","r=l"
oApi.Register "kernel32.dll","lstrcat","f=s","i=ws","r=l"
oApi.Register "kernel32.dll","RtlMoveMemory","f=s","i=lll","r=l"

hFile=oApi.CreateFileMappingA(INVALID_HANDLE_VALUE,Null,PAGE_READWRITE,
0,4096,sSharedSpace&"")
lMapView=oApi.MapViewOfFile(hFile,FILE_MAP_WRITE,0,0,0)
sTest="This is an omen999 share test"
SetShared sTest
Msgbox "Server waiting... "
oApi.UnmapViewOfFile lMapView
oApi.CloseHandle hFile



client.vbs:
Option Explicit
Const INVALID_HANDLE_VALUE=-1
Const PAGE_READWRITE=4
Const FILE_MAP_WRITE=2

Function GetBSTRPtr(ByRef sData)
Dim pSource,pDest
pSource=oApi.lstrcat(sData,"")
pDest=oApi.lstrcat(GetBSTRPtr,"")
GetBSTRPtr=CLng(0)
oApi.RtlMoveMemory pDest+8,pSource+8,4
End Function

Function GetShared()
GetShared=String(58,chr(0))
oApi.RtlMoveMemory GetBSTRPtr(GetShared),lMapView,58
End Function

Dim oApi,hFile,sSharedSpace,lMapView
Dim sTest 'shared string variable
sSharedSpace="ACME"

Set oApi=CreateObject("DynamicWrapper")
oApi.Register
"kernel32.dll","CreateFileMappingA","f=s","i=hlllls","r=h"
oApi.Register "kernel32.dll","MapViewOfFile","f=s","i=hllll","r=l"
oApi.Register "kernel32.dll","UnmapViewOfFile","f=s","i=l","r=l"
oApi.Register "kernel32.dll","CloseHandle","f=s","i=h","r=l"
oApi.Register "kernel32.dll","lstrcat","f=s","i=ws","r=l"
oApi.Register "kernel32.dll","RtlMoveMemory","f=s","i=lll","r=l"

hFile=oApi.CreateFileMappingA(INVALID_HANDLE_VALUE,Null,PAGE_READWRITE,
0,4096,sSharedSpace&"")
lMapView=oApi.MapViewOfFile(hFile,FILE_MAP_WRITE,0,0,0)
sTest=GetShared
oApi.UnmapViewOfFile lMapView
oApi.CloseHandle hFile
Msgbox sTest

.



Relevant Pages

  • Re: sharing variables between scripts with dynawrap case study #3
    ... server.vbs which set shared string and client.vbs which get shared ... Function GetBSTRPtr(ByRef sData) ... Dim oApi,hFile,sSharedSpace,lMapView ... Dim sTest 'shared string variable ...
    (microsoft.public.scripting.vbscript)
  • Internet Connection Issue
    ... incapsulates a local intranet server side program called PeopleSoft ... Private Function Nav(sURL As String) ... Dim oRegEx As RegExp ... Dim sData As String ...
    (microsoft.public.excel.programming)
  • Re: File Streams
    ... this chunk has obviously a structure whose format is ... Public Function ReadSummaryInformation(sFile As String) As String ... Dim sData As String ...
    (microsoft.public.vb.general.discussion)
  • Re: remove add-in entry via registry
    ... There is just one bit that won't work with Excel and that is the keyword ... > (ByVal lpClassName As String, ByVal lpWindowName As String) As Long ... > Dim bUndo As Boolean ... > Dim sData As String 'Text for Data column in Registry ...
    (microsoft.public.excel.programming)
  • Re: extract names of all subs and functions
    ... Dim lNum As Long ... Dim sData As String ...
    (microsoft.public.vb.general.discussion)