Page 2 of 3 <123>
Topic Options
#103822 - 2003-08-16 01:59 AM Re: String Challenge
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
actually, the vbs way looks 100% better.
string stops where nul is found.
that is the rule.

that has happened.
henri has braken the rules by disabling nul-char from us but basically the 2 function just the same.
_________________________
!

download KiXnet

Top
#103823 - 2003-08-16 10:58 PM Re: String Challenge
kholm Offline
Korg Regular
*****

Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
My gues is that KiXtart always allocates 32.000 bytes for a string variable, but the variable is treated as a 'SZ_STRING'

Mening: End of variable contents to Show/Read/Write is the first 'ZERO' value.

Since KiXtart is a script-language there is no heap, only a stack. So our best friend (Ruud) treats the variables like C/C+/C++
This automatically rules out the use of 'Null'/'ZERO' values in strings, since they are string terminators.

Maybe we should ask Ruud to add some BinString functions, (I know) this has been suggested many times before.
But maybe it could be achieved by an optional parameter to the string functions to imply a bin-string, witch would require a string to be ended with a 'double ZERO'

Or Maybe a new VarType of BinString that wil not be ended with a single 'ZERO', but has to end with a 'double ZERO'

-Erik

Top
#103824 - 2003-08-16 11:11 PM Re: String Challenge
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
the new vartype sounds better option.
afaik, vbs and kix works just the same but seems that ruud has disabled the usage of chr(0) so instead of cutting the string (like in vbs) kix just leaves the nul out.
_________________________
!

download KiXnet

Top
#103825 - 2003-08-16 11:46 PM Re: String Challenge
kholm Offline
Korg Regular
*****

Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
The new vartype would be good. BUT, how do we declare it!

One of the functions that would be nice to have a 'Bin-Flag' on would be ReadLine():

ReadLine('Handle')

Could Be:
ReadLine('Handle','Bin')

Then Readline() should not stop at: \x1a (EndOfFile) but read on til 'DOUBLE ZERO' is found.

-Erik

Top
#103826 - 2003-08-18 03:43 AM Re: String Challenge
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
The 'double zero' will not work in my case as MAC addresses can contain multiple continous binary zeros. It would work, however, if the length of the binary string is being determined ahead of time and then treating the string more like an array where each array element represents a character.

[ 18. August 2003, 16:21: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#103827 - 2003-08-18 10:13 AM Re: String Challenge
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
quote:
woudl work, however if the length of the binary string is beign determined ahead of time
And that is of course the only way it will work.

Maybe we should avoid the word "string" to describe this, as it is confusing the issue.

What you need is an abitrary binary object. It is not a string. Handling and object as a string is simply taking a binary object an adding some rules to it - the simplest of which is that it is null terminated.

A "string" object is a very simple beast. It has a start (pointer to memory location) and content (the string data). The size of the string is determined by the data (and available memory). This means that a string is represented in coding terms by a simple pointer to memory and nothing else.

To contain arbitrary binary data, the object needs more information contained within the object itself. Specifically it requires an "end" or more likely a "length" attribute. This must be a property of the object, as it needs to be passed along with it.

This is going to make things very complicated, as something like KiXtart can deal with binary objects represented as COM automation objects, but something like Winsock will be expecting two simple values - a pointer and a length.

What you could try is constructing an automation object which creates a buffer for arbitrary binary data, and a length parameter. Assign values to it using an array or C-escaped type declarations, and then pass the individual parts on. You won't be able to manipulate them in KiXtart (unless you follow the string rules) but you may be able to pass them for handling by COM.

A final note about Winsock. When I was looking at using it some time ago I had problems. Either the library wasn't initialising, or wasn't dealing with I/O because it was expecting to be dealing with event driven code. That was why I ended up playing with the Catalyst product.

The best solution for this is to code a wrapper COM Automation object which calls the socket library directly. The wrapper object can include all the support routines you need for automatically converting to and from native KiXtart types.

As a spooky aside this is exactly what I was working on before real work intervened and I had to mothball it.

Top
#103828 - 2003-08-18 02:20 PM Re: String Challenge
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Jens,

quote:

BTW, the COM-object where I need this is MSWinsock.Winsock(), which I tried to use to do a Wake-On-LAN. However, MAC addresses do contain CHR(0), thus currently a no-go for KiXtart-COM

Do you have any example code written in VBS or JS that uses this COM component, and that manages to pass a string with null chars ?

Richard,

Yeah, if one was to build a COM wrapper for this, would probably just suggest wrapping this in an array and pass binary data like this:

$Object.Address = 0,3,23,0,44,255,0 ...

-Shawn

[ 18. August 2003, 14:23: Message edited by: Shawn ]

Top
#103829 - 2003-08-18 04:25 PM Re: String Challenge
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
VB Code ( http://cwashington.netreach.net/depo/view.asp?Index=415&ScriptType=component ):
code:
<?xml version="1.0"?>
<component>

<?component error="true" debug="true"?>

<registration
description="MagicPacket"
progid="MagicPacket.WSC"
version="1.01"
classid="{37bab79c-5e27-4cf2-b0e2-73979683a479}"
>
</registration>

<public>
<property name="IPBroadcastAddress">
<put/>
</property>
<property name="MacAddress">
<get/>
<put/>
</property>
<method name="Send">
</method>
</public>

<script language="VBScript">
<![CDATA[
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Component: MagicPacket.WSC
' Properties: IPBroadcastAddress:
' The IP Broadcast Address of the host you would like to wake up.
This is typically
' something like 10.10.118.255
' MacAddress:
' The Hardware address of the host you would like to wake up. This can either
' be in the form 11:22:33:44:55:66 (as it is in SMS) or 11-22-33-44-55-66 as is
' the output from getmac.exe
' Methods: Send
' Sends the packet, and hopefully wakes up the machine
' Requires: mswinsck.dll
' Comes with VisualStudio
'
' Example: dim o
' Set o = CreateObject("MagicPacket.WSC")
' o.IPBroadcastAddress = "10.10.224.255"
' o.macaddress = "00-08-C7-59-2D-17"
' o.send
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
dim IPBroadcastAddress
dim MacAddress

function put_IPBroadcastAddress(newValue)
IPBroadcastAddress = newValue
end function

function get_MacAddress()
get_MacAddress = MacAddress
end function

function put_MacAddress(newValue)
MacAddress = newValue
end function

function Send()
SendWakeUp MacAddress, IPBroadcastAddress
end function

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Function: parseMac
' Params: Hardare address of network adapter in either colon(:) or dash(-) delimited form
' Return: Array of byte size mac address elements for later processing
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Function parseMAC(strMacAddr)
Dim arMacAddr

Select Case Len(strMacAddr)
Case 17
arMacAddr = Split(strMacAddr, ":")
If Ubound(arMacAddr) <> 5 Then
arMacAddr = Split(strMacAddr, "-")
If Ubound(arMacAddr) <> 5 Then
parseMac = -1 'Error
Else
parseMac = arMacAddr
End If
Else
parseMac = arMacAddr
End If

Case Else
parseMac = -1 'Error
End Select
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Function: CreatePacket
' Params: array of bytes representing Mac address of target
' Return: String of data representing Magic Packet data
' Notes: Magic Packet is six bytes of chr(&HFF) folowed by 16 copies of the target adapter's
' Mac address
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Function CreatePacket(arMacAddr)
Dim Item
Dim strTemp
Dim strData

For Each Item in arMacAddr
Item = "&H" & Item
strTemp = strTemp & chr(Item)
Next
For i = 1 to 16
strData = strData & strTemp
Next
CreatePacket = String(6, &HFF) & strData
End Function

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Function: SendWakeUp
' Params: Mac Address of target machine, IP Broadcast address of target machine
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Function SendWakeUp(MacAddr, BCastAddr)
Dim objSocket
Set objSocket = CreateObject("MSWinsock.Winsock")
objSocket.Protocol = 1 'UDP
objSocket.RemoteHost = BCastAddr
objSocket.SendData CreatePacket(ParseMac(MacAddr))
objSocket.Close
End Function
]]>
</script>

</component>

KiXtart Code (not functional):
code:
; to be run with KiXtart 4.21 or later

break on
cls
dim $iRC
$iRC=SetOption("WrapAtEOL","On")
$iRC=SetOption("Explicit","On")
$iRC=SetOption("NoVarsInStrings","On")

dim $sMAC, $sBCast

$sMAC=@ADDRESS
$sBCast='128.197.181.255'
? 'MAC Address = '+$sMAC
? 'Broadcast Address = '+$sBCast

$iRC=WakeOnLAN($sMAC, $sBCast)
? 'Error '+@ERROR+' - '+@SERROR
? 'WakeOnLAN = '+$iRC
exit 0

function WakeOnLAN($sMAC, $sBCast, optional $bWait)
dim $iIndex, $asMAC[5], $sMagicPacket, $sByte
dim $objSocket

; format the MAC address
select
case len($sMAC)=12
for $iIndex=0 to 5
$asMAC[$iIndex]=substr($sMAC,$iIndex*2+1,2)
next
case len($sMAC)=17
select
case instr($sMAC,':')
$asMAC=split($sMAC,':')
case instr($sMAC,'-')
$asMAC=split($sMAC,'-')
case 1
exit 87
endselect
case 1
exit 87
endselect

; create the magic packet (six bytes of FF followed by 16 copies of the MAC address
$sMAC=''
for each $sByte in $asMAC
? 'Byte = '+$sByte+' = '+chr(val('&'+$sByte))
$sMAC=$sMAC+chr(val('&'+$sByte))
next
? 'MAC = ('+len($sMAC)+') = '+$sMAC
redim $sMagicPacket[6], $WakeOnLAN[16]
$sMagicPacket=join($sMagicPacket,chr(&FF))
$WakeOnLAN=join($WakeOnLAN,$sMAC)
$sMagicPacket=$sMagicPacket+$WakeOnLAN
? 'Magic Packet = '+len($sMagicPacket)

; create the Winsock object and send the magic packet
$objSocket=createobject('MSWinsock.Winsock')
$objSocket.Protocol = 1
$objSocket.RemoteHost = $sBCast
$objSocket.SendData = $sMagicPacket
$objSocket.Close
$objSocket = 0

$WakeOnLAN=@ERROR
exit @ERROR
endfunction

_________________________
There are two types of vessels, submarines and targets.

Top
#103830 - 2003-08-19 01:05 AM Re: String Challenge
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Just started looking at this bit of code - think it holds the key. Since the SendData method takes a string, then this routine is somehow constructing a string containing nulls ?

Whats with the sixteen times mac address thingy ? Is that part of the trick or just something to do with WOL ?

code:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Function: CreatePacket
' Params: array of bytes representing Mac address of target
' Return: String of data representing Magic Packet data
' Notes: Magic Packet is six bytes of chr(&HFF) folowed by 16 copies of the target adapter's
' Mac address
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Function CreatePacket(arMacAddr)
Dim Item
Dim strTemp
Dim strData

For Each Item in arMacAddr
Item = "&H" & Item
strTemp = strTemp & chr(Item)
Next
For i = 1 to 16
strData = strData & strTemp
Next
CreatePacket = String(6, &HFF) & strData
End Function



[ 19. August 2003, 01:07: Message edited by: Shawn ]

Top
#103831 - 2003-08-19 01:33 AM Re: String Challenge
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Jens, is this the documentation for the control in question ?

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/mswnsk98/html/vbobjwinsockcontrol.asp

Looks as if SendData it can also accept the infamous "byte array" that Kixtart also doesn't support [Wink]

errggg

Top
#103832 - 2003-08-19 01:40 AM Re: String Challenge
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Found a WinSock wrapper COM object called ActiveSocket that allows you to produce code like this:

code:
' *****************************************************
' Example4: Wake Up on LAN
' Note: Use an existing MAC address
' (c) Copyright 2001 by ActiveXperts Software
' http://www.activexperts.com
' *****************************************************

Set wObj = CreateObject("ActivXperts.WOL")

WScript.Echo "ActiveSocket " & wObj.Version & " demo."
WScript.Echo "Expiration date: " & wObj.ExpirationDate & vbCrLf

wObj.WakeUp "00-10-4B-BA-7A-51"
WScript.Echo "WakeUp: result = " & wObj.LastError

Costs money though, which kinda sucks.

-Shawn

Top
#103833 - 2003-08-19 01:44 AM Re: String Challenge
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Would it be acceptable for me to provide this functionality in Win32Admin.DLL? I think I can do if the code posted above works except for the nulls.

I know I can process chr(0)in Perl.

[ 19. August 2003, 01:46: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#103834 - 2003-08-19 01:46 AM Re: String Challenge
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Why not just do the WakeUp call (no pun intended) and take a MAC address as a string ? Do the nitty-gritty dirty stuff in your component.
Top
#103835 - 2003-08-19 01:48 AM Re: String Challenge
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
That would be what I expected would happen...take mac return did it wake up or not.

But I need to understand what the nitty gritty is. I haven't been following the WOL stuff.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#103836 - 2003-08-19 01:59 AM Re: String Challenge
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Jens posted the vbs (wsc) source and converted kixscript code up above in this thread. There are a few other examples on the web. Wonder maybe if any perl examples.
Top
#103837 - 2003-08-19 02:02 AM Re: String Challenge
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
S-ingTFW... [Wink]

I will see what turns up.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#103838 - 2003-08-19 02:54 AM Re: String Challenge
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
So, did you find anything during your S of the FW ?
Top
#103839 - 2003-08-19 03:04 AM Re: String Challenge
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Who can test the new DLL with Win32Admin.WakeUp($mac [,$ip] [,$port])

Default IP is broadcast "255.255.255.255"
default port is 9991
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#103840 - 2003-08-19 04:12 AM Re: String Challenge
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
I was just hoping to get away without registering another DLL. [Frown]

I guess, I'll have to use Howard's DLL then [Smile]
_________________________
There are two types of vessels, submarines and targets.

Top
#103841 - 2004-03-30 08:25 AM Re: String Challenge
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Jens,

Did you ever try Howard's DLL? Did it work or not?

Can or would it work with the PendingFileRenameOperation?

Top
Page 2 of 3 <123>


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2375 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.04 seconds in which 0.014 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org