Σάββατο 18 Φεβρουαρίου 2023

Revision 15, Version 12 (Varptr() function)

 This revision remove a bug on Hex conversion for long long types. Also introduce the VarPtr() and the first try to use interfaces from known objects types.

enum rettypes {
vt_Unknown=13&
}
declare SHCreateMemStream lib "shlwapi.#12" {long init, long cbinit} as vt_Unknown
a=buffer("this.gif")
method a, "ExportToByte" as b
with b, "ArrPtr" as arrptr()
c=SHCreateMemStream(arrptr(0), len(a))
? type$(c)
d=getobject("stole","stdpicture")
? type$(d)


OutPut:
UnKnown
Picture


Example in info (VarPtr)

// these two functions expect on the second argument byvalue integer and Long type value. (only Long support for automatic conversion this version of M2000)
declare PutMem2 lib "msvbvm60.PutMem2" {long addr, newval} ' newval has to be integer
declare PutMem4 lib "msvbvm60.PutMem4" {long addr, Long newval}
// these two functions expect on the second argument by refernece so we have Long,
//             and we have to place Varptr() for at least the Bytes which the functions replace with new value
declare GetMem2 lib "msvbvm60.GetMem2" {long addr, long retValue}
declare GetMem4 lib "msvbvm60.GetMem4" {long addrl, long retVaule}
integer a[2], nv
With a, "ArrPtr" as global a.ArrPtr()
def aPtr(x as long)=a.ArrPtr(0)+x*2&
Hex "Varptr(a[0]) = ";a.ArrPtr(0), aPtr(0)
nv=123
call PutMem2(a.ArrPtr(0), nv)
call PutMem2(a.ArrPtr(0)+2&, nv+1%)
call PutMem2(a.ArrPtr(0)+4&, nv+2%)
Print a[0]=123, a[1]=124, a[2]=125
hex aPtr(0)
hex aPtr(1)
hex aPtr(2)


// variables
// all variable use a variant type container, but the VarPtr() return the address of the value
// excpet for Variant type which return the address of the first byte of the variant
// also Decimal type has 16 bytes, 18 for value and 2 for the type (always is a part of variant)
// M2000 knows which variable can change type (is variant by use) and which can't (has type)


long K=100
Print K
Call PutMem4(varptr(K), 1000&)
Print K
variant Z=100&
// We now that long value is at an offset of 8
Call PutMem4(varptr(Z)+8, 1234&)
Print Z
long retval
// We can read the type of variant (from the first two bytes)
Call GetMem2(varptr(Z), varptr(retval))
Print retval=3 ' vt_long
Call GetMem4(varptr(Z)+8, varptr(retval))
Print retval=1234

Δεν υπάρχουν σχόλια:

Δημοσίευση σχολίου

You can feel free to write any suggestion, or idea on the subject.