Charles, this is part of a script i made, i made it to test that passing all types of parameters to modules behave correctly when passed BYREF and when passed BYVAL.
It works fine with STRING, but with WSTRING it crashes before the code is able to do much.
Heres for STRING:
$ filename "C:\Users\Diamante\Documents\PluriBASIC\Clean\SMALLER.exe"
uses rtl32
uses console
DIM STRING ¤SYSTEM_UDT_OFFSETS(0)
STRING ¤TMPS = "" ' a temporary string.
DECLARE FUNCTION ¤GetLastError Lib "Kernel32.dll" Alias "GetLastError" () AS LONG
DECLARE FUNCTION ¤GetAsyncKeyState Lib "User32.dll" Alias "GetAsyncKeyState" (ByVal vKey AS LONG) AS short
DECLARE SUB ¤Sleep lib "Kernel32.dll" alias "Sleep" (dword mSec)
function ¤INI_QUAD(dword v1, v2) as quad
quad v = 0
copy @v+0, @v2, 4
copy @v+4, @v1, 4
return v
end function
DECLARE FUNCTION ¤OpenProcess Lib "KERNEL32.DLL" Alias "OpenProcess" (ByVal dwDesiredAccess AS DWORD, ByVal bInheritHandle AS LONG, ByVal dwProcessId AS SYS) AS SYS
DECLARE FUNCTION ¤TerminateProcess Lib "KERNEL32.DLL" Alias "TerminateProcess" ( ByVal hProcess AS SYS, ByVal uExitCode AS DWORD) AS LONG
DECLARE FUNCTION ¤CloseHandle Lib "KERNEL32.DLL" Alias "CloseHandle" (ByVal hObject AS SYS) AS LONG
DECLARE FUNCTION ¤GetCurrentProcessId Lib "KERNEL32.DLL" Alias "GetCurrentProcessId" () AS SYS
MACRO ¤SET_ERR(n)
Err.err = n
Err.erl = Err.erp
END MACRO
MACRO ¤ONERR(l, e)
Err.err = e
IF (Err.err>0) THEN
Err.ers = Err.erp
Err.erl = l
IF Err.Oe1 THEN
JMP Err.Oe1
ELSEIF Err.Oe2 THEN
CALL Err.Oe2
END IF
else
Err.ers = ""
Err.erl = 0
END IF
END MACRO
MACRO ERRCLEAR
Err.err = 0
Err.erl = 0
Err.ers = ""
END MACRO
CLASS ¤SYSERR
public sys Oe1 = 0
public sys Oe2 = 0
public int err = 0
public int erl = 0
public string erp = ""
public string ers = ""
END CLASS
DECLARE FUNCTION ¤WriteConsole LIB "KERNEL32.DLL" ALIAS "WriteFile" (BYVAL hFile AS SYS, lpBuffer AS ANY, BYVAL nNumberOfBytesToWrite AS dword, lpNumberOfBytesWritten AS dword, lpReserved AS long) AS LONG
DECLARE FUNCTION ¤AllocConsole LIB "KERNEL32.DLL" ALIAS "AllocConsole" () AS LONG
DECLARE FUNCTION ¤FlushFileBuffers LIB "KERNEL32.DLL" ALIAS "FlushFileBuffers" (BYVAL hFile AS SYS) AS LONG
DECLARE FUNCTION ¤GetStdHandle LIB "KERNEL32.DLL" Alias "GetStdHandle" (ByVal nStdHandle AS DWORD) AS SYS
' STARTS PLURIBASIC_PREPARE.BIN
' This code is executed before anything else, if you want to do something after defining other things, see PLURIBASIC_INIT
#DEF HANDLE SYS
TYPE ¤SYSNMHDR
hwndFrom AS SYS
idFrom AS SYS
Code AS DWORD
END TYPE
class ¤SYSF
FUNCTION CONSTRUCTOR()
END FUNCTION
END CLASS
new ¤SYSF EXE()
' END OF PLURIBASIC_PREPARE.BIN
' STARTS STRINGN.BIN
//Assigns a truncated null terminated string.
MACRO ¤STRN_SET(v, c, l b)
string b = c
if len(b) > l then
b = left(b, l)
elseif len(b) < l then
b += space(l-len(b))
end if
v = b
END MACRO
' END OF STRINGN.BIN
' STARTS PRINTR.BIN
SUB ¤INITCONSOLE()
STATIC Allc AS LONG
IF Allc=0 THEN
¤AllocConsole()
Allc = 1
END IF
END SUB
MACRO ¤STDOUT()
INT lWritten = 0
SYS hFile = 0
INT Btc = 0
STRING TTsnd = ""
¤INITCONSOLE()
¤Sleep(0)
hFile = ¤GetStdHandle(-11)
FOR Btc = 1 TO 50
IF ((Btc*32000)-31999) > len(s) THEN EXIT FOR
TTsnd = MID$(s, ((Btc*32000)-31999), 32000)
¤WriteConsole(hFile, ByVal StrPtr(TTsnd), byval Len(TTsnd), lWritten, ByVal 0)
NEXT Btc
¤FlushFileBuffers(hFile)
END MACRO
SUB PRINTR(BYVAL s AS WSTRING, byval b as string)
¤STDOUT()
END SUB
SUB PRINTR(BYVAL s AS STRING, byval b as string)
¤STDOUT()
END SUB
SUB PRINTR(CHAR *c, byval string b)
string s = c
¤STDOUT()
END SUB
'SUB PRINTR(WCHAR *c, byval string b)
' string s = c
' ¤STDOUT()
'END SUB
' END OF PRINTR.BIN
' STARTS PLURIBASIC_INIT.BIN
' This code is executed before anything else, if you want to do something before nything else, see PLURIBASIC_PREPARE
' END OF PLURIBASIC_INIT.BIN
' STARTS LCASE$.BIN
' LCASE$ stock code (not required by oxygen)
' END OF LCASE$.BIN
' STARTS CALLBACKDATA.BIN
' END OF CALLBACKDATA.BIN
DECLARE SUB QUERYVARIABLESTRING(BYVAL P1 AS STRING, P2 AS STRING)
DECLARE SUB TESTVARIABLESTRING()
DECLARE FUNCTION PBMAIN() AS LONG
STRING ¤¤on16k36
STRING ¤¤mn1ak36
' Initializes various things in the script.
FUNCTION PluriBASIC_Initialize() AS LONG
END FUNCTION
SUB QUERYVARIABLESTRING(STRING »p1, STRING *p2)
¤SYSERR Err
STRING p1 = »p1
IF (p1=¤¤on16k36) THEN
PRINTR("*Success " & "Passing byval " & LCASE("STRING") & " to a module" & chr(13,10), chr(13, 10))
ELSE
PRINTR("*Failure " & "Passing byval " & LCASE("STRING") & " to a module" & " in " & "QUERYVARIABLESTRING" & "*" & chr(13,10), chr(13, 10))
PRINTR(" got " & p1 & " but expected " & ¤¤on16k36 & chr(13,10), chr(13, 10))
END IF
IF (p2=¤¤on16k36) THEN
PRINTR("*Success " & "Passing byref " & LCASE("STRING") & " to a module" & chr(13,10), chr(13, 10))
ELSE
PRINTR("*Failure " & "Passing byref " & LCASE("STRING") & " to a module" & " in " & "QUERYVARIABLESTRING" & "*" & chr(13,10), chr(13, 10))
PRINTR(" got " & p2 & " but expected " & ¤¤on16k36 & chr(13,10), chr(13, 10))
END IF
p2 = (¤¤mn1ak36)
END SUB
SUB TESTVARIABLESTRING()
¤SYSERR Err
STRING p1
STRING p2
p1 = ¤¤on16k36
p2 = ¤¤on16k36
IF (p1=¤¤on16k36) THEN
PRINTR("*Success " & "Default value assignation for " & LCASE("STRING") & chr(13,10), chr(13, 10))
ELSE
PRINTR("*Failure " & "Default value assignation for " & LCASE("STRING") & " in " & "TESTVARIABLESTRING" & "*" & chr(13,10), chr(13, 10))
PRINTR(" got " & p1 & " but expected " & ¤¤on16k36 & chr(13,10), chr(13, 10))
END IF
QUERYVARIABLESTRING(p1, p2)
IF (p1=¤¤on16k36) THEN
PRINTR("*Success " & "Retaining original value after passed byval" & chr(13,10), chr(13, 10))
ELSE
PRINTR("*Failure " & "Retaining original value after passed byval" & " in " & "TESTVARIABLESTRING" & "*" & chr(13,10), chr(13, 10))
PRINTR(" got " & p1 & " but expected " & ¤¤on16k36 & chr(13,10), chr(13, 10))
END IF
IF (p2=¤¤mn1ak36) THEN
PRINTR("*Success " & "Retaining changes made in module when passed byref" & chr(13,10), chr(13, 10))
ELSE
PRINTR("*Failure " & "Retaining changes made in module when passed byref" & " in " & "TESTVARIABLESTRING" & "*" & chr(13,10), chr(13, 10))
PRINTR(" got " & p2 & " but expected " & ¤¤mn1ak36 & chr(13,10), chr(13, 10))
END IF
PRINTR("-------", chr(13, 10))
END SUB
FUNCTION PBMAIN() AS INT
INT ¤RETVAL = 0
¤SYSERR Err
¤¤on16k36 = ("ORIG")
¤¤mn1ak36 = ("MODIFIED")
TESTVARIABLESTRING()
PRINTR("DONE: " & "INFO", "</br>")
RETURN ¤RETVAL
END FUNCTION
PBMAIN() ' invoke entry point
And here is for WSTRING:
$ filename "C:\Users\Diamante\Documents\PluriBASIC\Clean\SMALLER.exe"
uses rtl32
uses console
DIM STRING ¤SYSTEM_UDT_OFFSETS(0)
STRING ¤TMPS = "" ' a temporary string.
DECLARE FUNCTION ¤GetLastError Lib "Kernel32.dll" Alias "GetLastError" () AS LONG
DECLARE FUNCTION ¤GetAsyncKeyState Lib "User32.dll" Alias "GetAsyncKeyState" (ByVal vKey AS LONG) AS short
DECLARE SUB ¤Sleep lib "Kernel32.dll" alias "Sleep" (dword mSec)
function ¤INI_QUAD(dword v1, v2) as quad
quad v = 0
copy @v+0, @v2, 4
copy @v+4, @v1, 4
return v
end function
DECLARE FUNCTION ¤OpenProcess Lib "KERNEL32.DLL" Alias "OpenProcess" (ByVal dwDesiredAccess AS DWORD, ByVal bInheritHandle AS LONG, ByVal dwProcessId AS SYS) AS SYS
DECLARE FUNCTION ¤TerminateProcess Lib "KERNEL32.DLL" Alias "TerminateProcess" ( ByVal hProcess AS SYS, ByVal uExitCode AS DWORD) AS LONG
DECLARE FUNCTION ¤CloseHandle Lib "KERNEL32.DLL" Alias "CloseHandle" (ByVal hObject AS SYS) AS LONG
DECLARE FUNCTION ¤GetCurrentProcessId Lib "KERNEL32.DLL" Alias "GetCurrentProcessId" () AS SYS
MACRO ¤SET_ERR(n)
Err.err = n
Err.erl = Err.erp
END MACRO
MACRO ¤ONERR(l, e)
Err.err = e
IF (Err.err>0) THEN
Err.ers = Err.erp
Err.erl = l
IF Err.Oe1 THEN
JMP Err.Oe1
ELSEIF Err.Oe2 THEN
CALL Err.Oe2
END IF
else
Err.ers = ""
Err.erl = 0
END IF
END MACRO
MACRO ERRCLEAR
Err.err = 0
Err.erl = 0
Err.ers = ""
END MACRO
CLASS ¤SYSERR
public sys Oe1 = 0
public sys Oe2 = 0
public int err = 0
public int erl = 0
public string erp = ""
public string ers = ""
END CLASS
DECLARE FUNCTION ¤WriteConsole LIB "KERNEL32.DLL" ALIAS "WriteFile" (BYVAL hFile AS SYS, lpBuffer AS ANY, BYVAL nNumberOfBytesToWrite AS dword, lpNumberOfBytesWritten AS dword, lpReserved AS long) AS LONG
DECLARE FUNCTION ¤AllocConsole LIB "KERNEL32.DLL" ALIAS "AllocConsole" () AS LONG
DECLARE FUNCTION ¤FlushFileBuffers LIB "KERNEL32.DLL" ALIAS "FlushFileBuffers" (BYVAL hFile AS SYS) AS LONG
DECLARE FUNCTION ¤GetStdHandle LIB "KERNEL32.DLL" Alias "GetStdHandle" (ByVal nStdHandle AS DWORD) AS SYS
' STARTS PLURIBASIC_PREPARE.BIN
' This code is executed before anything else, if you want to do something after defining other things, see PLURIBASIC_INIT
#DEF HANDLE SYS
TYPE ¤SYSNMHDR
hwndFrom AS SYS
idFrom AS SYS
Code AS DWORD
END TYPE
class ¤SYSF
FUNCTION CONSTRUCTOR()
END FUNCTION
END CLASS
new ¤SYSF EXE()
' END OF PLURIBASIC_PREPARE.BIN
' STARTS WSTRING.BIN
//assigns a truncated null terminated string.
MACRO ¤WSTR_SET(v, c, l b)
wstring b = c
if len(b) > l then b = left(b, l)
v = b
END MACRO
' END OF WSTRING.BIN
' STARTS PRINTR.BIN
SUB ¤INITCONSOLE()
STATIC Allc AS LONG
IF Allc=0 THEN
¤AllocConsole()
Allc = 1
END IF
END SUB
MACRO ¤STDOUT()
INT lWritten = 0
SYS hFile = 0
INT Btc = 0
STRING TTsnd = ""
¤INITCONSOLE()
¤Sleep(0)
hFile = ¤GetStdHandle(-11)
FOR Btc = 1 TO 50
IF ((Btc*32000)-31999) > len(s) THEN EXIT FOR
TTsnd = MID$(s, ((Btc*32000)-31999), 32000)
¤WriteConsole(hFile, ByVal StrPtr(TTsnd), byval Len(TTsnd), lWritten, ByVal 0)
NEXT Btc
¤FlushFileBuffers(hFile)
END MACRO
SUB PRINTR(BYVAL s AS WSTRING, byval b as string)
¤STDOUT()
END SUB
SUB PRINTR(BYVAL s AS STRING, byval b as string)
¤STDOUT()
END SUB
SUB PRINTR(CHAR *c, byval string b)
string s = c
¤STDOUT()
END SUB
'SUB PRINTR(WCHAR *c, byval string b)
' string s = c
' ¤STDOUT()
'END SUB
' END OF PRINTR.BIN
' STARTS PLURIBASIC_INIT.BIN
' This code is executed before anything else, if you want to do something before nything else, see PLURIBASIC_PREPARE
' END OF PLURIBASIC_INIT.BIN
' STARTS LCASE$.BIN
' LCASE$ stock code (not required by oxygen)
' END OF LCASE$.BIN
' STARTS CALLBACKDATA.BIN
' END OF CALLBACKDATA.BIN
DECLARE SUB QUERYVARIABLEWSTRING(BYVAL P1 AS WSTRING, P2 AS WSTRING)
DECLARE SUB TESTVARIABLEWSTRING()
DECLARE FUNCTION PBMAIN() AS LONG
WSTRING ¤¤on16k33
WSTRING ¤¤mn1ak33
' Initializes various things in the script.
FUNCTION PluriBASIC_Initialize() AS LONG
END FUNCTION
SUB QUERYVARIABLEWSTRING(WSTRING »p1, WSTRING *p2)
¤SYSERR Err
WSTRING p1 = »p1
IF (p1=¤¤on16k33) THEN
PRINTR("*Success " & "Passing byval " & LCASE("WSTRING") & " to a module" & chr(13,10), chr(13, 10))
ELSE
PRINTR("*Failure " & "Passing byval " & LCASE("WSTRING") & " to a module" & " in " & "QUERYVARIABLEWSTRING" & "*" & chr(13,10), chr(13, 10))
PRINTR(" got " & p1 & " but expected " & ¤¤on16k33 & chr(13,10), chr(13, 10))
END IF
IF (p2=¤¤on16k33) THEN
PRINTR("*Success " & "Passing byref " & LCASE("WSTRING") & " to a module" & chr(13,10), chr(13, 10))
ELSE
PRINTR("*Failure " & "Passing byref " & LCASE("WSTRING") & " to a module" & " in " & "QUERYVARIABLEWSTRING" & "*" & chr(13,10), chr(13, 10))
PRINTR(" got " & p2 & " but expected " & ¤¤on16k33 & chr(13,10), chr(13, 10))
END IF
p2 = (¤¤mn1ak33)
END SUB
SUB TESTVARIABLEWSTRING()
¤SYSERR Err
WSTRING p1
WSTRING p2
p1 = ¤¤on16k33
p2 = ¤¤on16k33
IF (p1=¤¤on16k33) THEN
PRINTR("*Success " & "Default value assignation for " & LCASE("WSTRING") & chr(13,10), chr(13, 10))
ELSE
PRINTR("*Failure " & "Default value assignation for " & LCASE("WSTRING") & " in " & "TESTVARIABLEWSTRING" & "*" & chr(13,10), chr(13, 10))
PRINTR(" got " & p1 & " but expected " & ¤¤on16k33 & chr(13,10), chr(13, 10))
END IF
QUERYVARIABLEWSTRING(p1, p2)
IF (p1=¤¤on16k33) THEN
PRINTR("*Success " & "Retaining original value after passed byval" & chr(13,10), chr(13, 10))
ELSE
PRINTR("*Failure " & "Retaining original value after passed byval" & " in " & "TESTVARIABLEWSTRING" & "*" & chr(13,10), chr(13, 10))
PRINTR(" got " & p1 & " but expected " & ¤¤on16k33 & chr(13,10), chr(13, 10))
END IF
IF (p2=¤¤mn1ak33) THEN
PRINTR("*Success " & "Retaining changes made in module when passed byref" & chr(13,10), chr(13, 10))
ELSE
PRINTR("*Failure " & "Retaining changes made in module when passed byref" & " in " & "TESTVARIABLEWSTRING" & "*" & chr(13,10), chr(13, 10))
PRINTR(" got " & p2 & " but expected " & ¤¤mn1ak33 & chr(13,10), chr(13, 10))
END IF
PRINTR("-------", chr(13, 10))
END SUB
FUNCTION PBMAIN() AS INT
INT ¤RETVAL = 0
¤SYSERR Err
¤¤on16k33 = ("ORIG")
¤¤mn1ak33 = ("MODIFIED")
TESTVARIABLEWSTRING()
PRINTR("DONE: " & "INFO", "</br>")
RETURN ¤RETVAL
END FUNCTION
PBMAIN() ' invoke entry point
At first I thought that some functions could be expecting a STRING instead of a WSTRING, but after i remarked everything that could use it,
the program still crashed. It could still be my fault, somehow, but...