Author Topic: DLLC Development  (Read 323 times)

0 Members and 1 Guest are viewing this topic.

John

  • Hero Member
  • *****
  • Posts: 2793
DLLC Development
« on: September 25, 2017, 07:28:00 PM »
Charles,

I've been thinking about DLLC lately and wonder if it could trend toward a generic FFI utility DLL other interpreters could use as well. I would still like to have a flavor of it that can be called as an extension module. We can gut the IUP and callback Script BASIC specific stuff as SBT now handles it with multiple IupLoop() threads. I would like to share Dave's VB COM OLE functionality from DLLC.

John

  • Hero Member
  • *****
  • Posts: 2793
Re: DLLC Development
« Reply #1 on: September 26, 2017, 11:51:07 AM »
I'm going to start thinning out DLLC focusing on its dynamic FFI extension module features.

John

  • Hero Member
  • *****
  • Posts: 2793
Re: DLLC Development
« Reply #2 on: September 26, 2017, 08:35:04 PM »
This was Charles initial Script BASIC program to test the following DLLC features.

  • LOADING LIBRARIES
  • MEASURING TIME FRACTIONAL SECONDS
  • DECLARING PROCEDURES
  • SHOW DLLC RECORDS
  • CREATING A COMPOUND TYPE
  • CREATING A COMPOUND VARIABLE (ARRAY OF 2 UNITS)
  • ASSIGNING VALUES
  • READING A MEMBER VALUE
  • WRITING A MEMBER VALUE
  • CALLING SUBS
  • CALLING FUNCTIONS
  • SB STRING / OLE STRING CONVERSIONS
  • EXPLICIT DISPOSAL OF BSTRING
  • ASCII / WIDE CONVERSIONS
  • GUID TEXT TO BINARY CONVERSION
  • RETURNING POINTERS TO STRUCTURES
  • QUAD VALUES ON A 32 BIT SYSTEM:  ARRAY OF 2 INTEGERS (LOW AND HIGH)


Code: OxygenBasic
  1.  
  2. includepath "$\inc\"
  3. '$filename "c:\ScriptBasic\modules\DLLCtestDLL.dll"
  4. $filename "DLLCtestDLL.dll"
  5. $dll
  6. include "RTL32.inc"
  7. include "Console.inc"
  8.  
  9. cr=chr(13,10)
  10.  
  11. extern export
  12.  
  13. sys cbk
  14.  
  15. function returnquad(sys n) as quad
  16. ==================================
  17. type t int l,u = quad q
  18. t v={n-1,n+1}
  19. return v.q
  20. end function
  21.  
  22.  
  23. function returnquadq(quad n) as quad
  24. ====================================
  25. int i at @n
  26. i++
  27. @i+=4
  28. i--
  29. return n
  30. end function
  31.  
  32. function returnquadqv(quad*n) as quad
  33. =====================================
  34. int i at @n
  35. i++
  36. @i+=4
  37. i--
  38. return n
  39. end function
  40.  
  41.  
  42. function SetCallBack(sys f)
  43. ===========================
  44. cbk=f
  45. end function
  46.  
  47. function MakeCallBack(sys n)
  48. ============================
  49. if cbk then call cbk n
  50. end function
  51.  
  52. function MakeCallBacks()
  53. ========================
  54. for i=1 to 5
  55.  MakeCallBack i
  56.  Sleep 500
  57. next
  58. end function
  59.  
  60.  
  61. function tic(sys* n) as sys
  62. ===========================
  63. sys i,h,le,lw
  64. string s="?"
  65. if n=1 then s="tick"
  66. if n=2 then s="tock"
  67. s+=chr(13,10)
  68. h=GetStdHandle -11 'write
  69. le=len s
  70. for i=1 to 5
  71. WriteConsole h,strptr s,le,@lw,0
  72. sleep 500
  73. next
  74. end function
  75.  
  76.  
  77. function stringbuf(char*b,sys le)
  78. =================================
  79. static string s="greeting from stringbffuf procedure / DLLtestDLL " chr(13) chr(10)
  80. ls=len s+2 'include terminating chars
  81. if ls>le then ls=le
  82. copy strptr b,strptr s,ls
  83. end function
  84.  
  85. function doublebyref(double*b)
  86. ==============================
  87. b*=2
  88. end function
  89.  
  90. function longbyref(long*b)
  91. ==========================
  92. b*=2
  93. end function
  94.  
  95. function returnfloat() as float
  96. ===============================
  97. return pi
  98. end function
  99.  
  100. function returndouble() as double
  101. =================================
  102. return pi
  103. end function
  104.  
  105. function passfloat(float f) as float
  106. ====================================
  107. return f
  108. end function
  109.  
  110. function passdouble(double f) as double
  111. =======================================
  112. return f
  113. end function
  114.  
  115. function returnbstring() as string
  116. ==================================
  117. function="This was an OLE/Bstring"
  118. end function
  119.  
  120. type rectangle
  121. ==============
  122. int top,left,right,bottom
  123. end type
  124.  
  125.  
  126. type guid
  127. =========
  128. a as dword
  129. b as word
  130. c as word
  131. d[8] as byte
  132. end type
  133.  
  134. function ReturnRectangle() as rectangle*
  135. ========================================
  136. static rectangle r={100,200,300,400}
  137. return @r
  138. end function
  139.  
  140. function rectanglearea(rectangle*r) as sys
  141. ==========================================
  142. /*
  143. int *s=@r-16
  144. string cr=chr (13,10)
  145. string ss="content:" cr
  146. for i=1 to 4
  147.   ss+=s[i] cr
  148. next
  149. print ss
  150. */
  151. return (r.right-r.left)*(r.bottom-r.top) 'top y=0 bottom y=window y
  152. end function
  153.  
  154. function showguid(guid *g1,*g2) as string
  155. =========================================
  156. return guidtxt(g1)+cr+guidtxt(g2)+cr
  157. end function
  158.  
  159.  
  160. function ArrayOfStrings(sys*buf,n) as sys
  161. =========================================
  162. static bstring s[10]={"one","two","three","four","five","six","","","",""}
  163. indexbase 1
  164. if n>10 then n=10
  165. for i=1 to n
  166.   buf[i]=strptr s[i]
  167. next
  168. end function
  169.  
  170. end extern
  171.  
  172. 'print returnbstring
  173.  

Code: Script BASIC
  1. ' PROPOSED ALTERNATIVE TO DYC
  2. ' supporting variables passed by reference
  3. ' supporting compound types
  4. ' supporting compound variables stored in SB strings
  5.  
  6. ' supported types:
  7. ' b bool
  8. ' c char
  9. ' d double precision float
  10. ' f float
  11. ' h handle
  12. ' i integer (32bit)
  13. ' p pointer
  14. ' s short (16bit) integer
  15. ' z null terminated string
  16.  
  17. ' supported calling conventions
  18. ' cdecl
  19. ' stdcall
  20.  
  21. ' * signifies pass variable by reference, otherwise by value
  22.  
  23. ' SB INTERFACE
  24.  
  25.   'DIAGNOSTICS  
  26.  declare sub dllshow alias "dllshow" lib "DLLC"
  27.   declare sub dllreco alias "dllreco" lib "DLLC"
  28.   declare sub dllsecs alias "dllsecs" lib "DLLC"
  29.   'CONSOLE
  30.  declare sub dllcnsl alias "dllcnsl" lib "DLLC"
  31.   declare sub dlllnpt alias "dlllnpt" lib "DLLC"
  32.   declare sub dllprnt alias "dllprnt" lib "DLLC"
  33.   declare sub dllcmnd alias "dllcmnd" lib "DLLC"
  34.   'DLL LINKAGE
  35.  declare sub dllfile alias "dllfile" lib "DLLC"
  36.   declare sub dllproc alias "dllproc" lib "DLLC"
  37.   'DLL CALLS
  38.  declare sub dllmeth alias "dllmeth" lib "DLLC"
  39.   declare sub dllcall alias "dllcall" lib "DLLC"
  40.   declare sub dllcald alias "dllcald" lib "DLLC"
  41.   declare sub dllcalt alias "dllcalt" lib "DLLC"
  42.   declare sub dllcobj alias "dllcobj" lib "DLLC"
  43.   declare sub dllcobt alias "dllcobt" lib "DLLC"
  44.   declare sub dllclbk alias "dllclbk" lib "DLLC"
  45.   'SBCALLS
  46.  declare sub dllprog alias "dllprog" lib "dllc"
  47.   declare sub dllendp alias "dllendp" lib "dllc"
  48.   declare sub dlltran alias "dlltran" lib "DLLC"
  49.   'CHANNELS AND THREADS
  50.  declare sub dllidat alias "dllidat" lib "DLLC"
  51.   declare sub dllodat alias "dllodat" lib "DLLC"
  52.   declare sub dllclos alias "dllclos" lib "DLLC"
  53.   declare sub dllwait alias "dllwait" lib "DLLC"
  54.   'DATA
  55.  declare sub dllsptr alias "dllsptr" lib "DLLC"
  56.   declare sub dlltype alias "dlltype" lib "DLLC"
  57.   declare sub dlldimv alias "dlldimv" lib "DLLC"
  58.   declare sub dllfill alias "dllfill" lib "DLLC"
  59.   declare sub dllgetm alias "dllgetm" lib "DLLC"
  60.   declare sub dllputm alias "dllputm" lib "DLLC"
  61.   declare sub dllptrm alias "dllptrm" lib "DLLC"
  62.   declare sub dllfrem alias "dllfrem" lib "DLLC"
  63.   'STRINGS / GUIDS
  64.  declare sub dlldelo alias "dlldelo" lib "DLLC"
  65.   declare sub dllostr alias "dllostr" lib "DLLC"
  66.   declare sub dllzstr alias "dllzstr" lib "DLLC"
  67.   declare sub dllastr alias "dllastr" lib "DLLC"
  68.   declare sub dllwstr alias "dllwstr" lib "DLLC"
  69.   declare sub dllcast alias "dllcast" lib "DLLC"
  70.   declare sub dllguid alias "dllguid" lib "DLLC"
  71.  
  72. 'TYPES
  73.  
  74. ' B boolean
  75. ' C character
  76. ' D double precision float
  77. ' F single precision float
  78. ' H handle
  79. ' I integer
  80. ' L long (4 byte) integer
  81. ' O bstring (as handle)
  82. ' Q quad integer (yet to be resolved)
  83. ' P pointer
  84. ' S short (2 byte) integer
  85. ' T user defined type
  86. ' Z sb zstring / SB string
  87.  
  88. ' add '*' for ptr/ passing byref
  89.  
  90. 'TITLE
  91.  
  92. print "DLLC SPEC / DEMO / TESTS:\n\n"
  93.  
  94. s=space(&h100)
  95.  
  96. 'LOADING LIBRARIES
  97.  
  98. mylib=dllfile("C:/ScriptBASIC/modules/DLLCtestDLL.dll")
  99.  
  100. ole32=dllfile("ole32.dll")
  101. print "MyLib " & mylib & "\n"
  102. print "ole32 " & ole32 & "\n"
  103.  
  104. 'MEASURING TIME FRACTIONAL SECONDS
  105.  
  106. t1=dllsecs()
  107.  
  108. 'DECLARING PROCEDURES
  109.  
  110. stringbuf        = dllproc(mylib,"stringbuf stdcall i=(c*buf, i bufsize) " )
  111. doublebyref      = dllproc(mylib,"doublebyref (d*num)"           )
  112. longbyref        = dllproc(mylib,"longbyref (l*num)"             )
  113. returnbstring    = dllproc(mylib,"returnbstring o=()"            )
  114. rectanglearea    = dllproc(mylib,"rectanglearea i=(t*rectangle)" )
  115. ReturnRectangle  = dllproc(mylib,"ReturnRectangle t*=()"         )
  116. showguid         = dllproc(mylib,"showguid z=(t*guidinput,t*guidinput)" )
  117. ReturnQuad       = dllproc(mylib,"returnquad q=(i value)" )
  118. ReturnQuadQ      = dllproc(mylib,"returnquadq q=(q value)" )
  119. ReturnQuadQV     = dllproc(mylib,"returnquadqv q=(q*value)" )
  120.  
  121. print "ReturnQuadQV "  & ReturnQuadQV & "\n"
  122.  
  123. 'TIMER
  124.  
  125. t2=dllsecs()
  126. print "Lapsed time Secs: " & t2-t1 & "\n\n"
  127.  
  128.  
  129. 'SHOW DLLC RECORDS
  130.  
  131. print dllreco(mylib) & "\n"
  132. print dllreco(stringbuf) & "\n"
  133.  
  134.  
  135. 'CREATING A COMPOUND TYPE
  136.  
  137. rectangle=dlltype("rectangle (i left,i top, i right, i bottom)")
  138. print dllreco(rectangle) & "\n"
  139.  
  140. SmallRectangle=dlltype("SmallRectangle (s left,s top, s right, s bottom)")
  141. print dllreco(rectangle) & "\n"
  142.  
  143. 'CREATING A COMPOUND VARIABLE (ARRAY OF 2 UNITS)
  144.  
  145. rect=dlldimv(rectangle,2)
  146.  
  147. print "Length of rect variables record: (16+4*2) " & len(rect) & "\n"
  148.  
  149. 'ASSIGNING VALUES
  150.  
  151. dllfill(rect,10,20,30,40)
  152.  
  153. 'READING A MEMBER VALUE
  154.  
  155. w=dllgetm(rect,1)
  156. print "rect left    (10) " & w & "\n"
  157. w=dllgetm(rect,2)
  158. print "rect top     (20) " & w & "\n"
  159. w=dllgetm(rect,3)
  160. print "rect right   (30) " & w & "\n"
  161. w=dllgetm(rect,4)
  162. print "rect bottom  (40) " & w & "\n"
  163.  
  164. 'WRITING A MEMBER VALUE
  165.  
  166. dllputm (rect,3,33)
  167. w=dllgetm(rect,3)
  168. print "rect right (33) " & w & "\n\n"
  169.  
  170. 'CALLING SUBS
  171.  
  172. z="Hello!" & space(100)
  173. dllcall(stringbuf,z,100)
  174. print z & "\n"
  175.  
  176. a=42
  177. dllcall(longbyref,a)
  178. print a & "\n"
  179. a=1.25
  180. dllcall(doublebyref,a)
  181. print a & "\n"
  182.  
  183.  
  184. 'CALLING FUNCTIONS
  185.  
  186. print "Rectangle Area: " & dllcall(rectanglearea,rect) & "\n"
  187. bs=dllcall(returnbstring)
  188. print "bstring handle: " & bs & "\n"
  189.  
  190. 'SB STRING / OLE STRING CONVERSIONS
  191.  
  192. z=dllzstr(bs)
  193. print z & "\n"
  194. bt=dllostr(z)
  195. print "bstring handle " & bt & "\n"
  196. y=dllzstr(bt)
  197. print y & "  (original bstring is automatically freed) \n\n"
  198.  
  199. 'EXPLICIT DISPOSAL OF BSTRING
  200.  
  201. bs=dllostr("ABCDEF")
  202. print "new bstring: handle=" & bs & "\n"
  203. dlldelo(bs)
  204. print "dispose bstring: handle=" & bs & "\n\n"
  205.  
  206.  
  207. 'ASCII / WIDE CONVERSIONS
  208.  
  209. az="abcdef"
  210. wz=dllwstr(az)
  211. print "Wide string (6 to 12) " & len(wz) & "\n"
  212. az=dllastr(wz)
  213. print "ascii string (12 to 6) " & len(az) & "\n"
  214. print az & "\n\n"
  215.  
  216. 'GUID TEXT TO BINARY CONVERSION
  217.  
  218. gu1=dllguid("{96749377-3391-11D2-9EE3-00C04F797396}")
  219. gu2=dllguid("{6C44DF74-72B9-4992-A1EC-EF996E0422D4}")
  220. print len(gu1) & "\n"
  221. print "GUID:\n" & dllcall(showguid,gu1,gu2) & "\n"
  222.  
  223. 'RETURNING POINTERS TO STRUCTURES
  224.  
  225. 'create pointer variable (third param flags ptr)
  226. 'a pointer to the Rectangle type:
  227. pRect=dlldimv(Rectangle,1,1)
  228.  
  229. 'call our test function to get the pointer
  230. p=dllcall(ReturnRectangle)
  231.  
  232. 'use dllptrm to assign pointer to pRect
  233. dllptrm(pRect,p)
  234.  
  235. 'display members of the rectangle
  236. w=dllgetm(pRect,1)
  237. print "pRect left    (100) " & w & "\n"
  238. w=dllgetm(pRect,2)
  239. print "pRect top     (200) " & w & "\n"
  240. w=dllgetm(pRect,3)
  241. print "pRect right   (300) " & w & "\n"
  242. w=dllgetm(prect,4)
  243. print "pRect bottom  (400) " & w & "\n"
  244.  
  245. 'QUAD VALUES ON A 32 BIT SYSTEM:  ARRAY OF 2 INTEGERS (LOW AND HIGH)
  246.  
  247. 'ar=dllCall(returnquad,16)
  248. 'print "Return Quad: " & ar[0] & "," & ar[1] &  "\n"
  249.  
  250. print "\n" & "DIRECT QUADS" & "\n" & "0x00000004 0x00000005" & "\n"
  251.  
  252. undef aq
  253. aq[0]=4
  254. aq[1]=5
  255. ap=dllCall(returnquadQ,aq)
  256. print "Return QuadQ: "  & ap[0] & "," & ap[1] &  "\n"
  257.  
  258. undef ap
  259. ap=dllCall(returnquadQ,aq)
  260. print "Return QuadQ: "  & ap[0] & "," & ap[1] &  "\n"
  261.  
  262. undef ar
  263. ar=dllCall(returnquadQ,ap)
  264. print "Return QuadQ: "  & ar[0] & "," & ar[1] &  "\n"
  265.  
  266. undef ar
  267. ar=dllCall(returnquadQV,ap)
  268. print "Return QuadQV: "  & ar[0] & "," & ar[1] &  "\n"
  269. print "Return QuadQV: "  & ap[0] & "," & ap[1] &  "\n"
  270.  
  271.  
  272. 'FREE ALL DLLS USED BY DLLC
  273.  
  274. dllfile
  275.  


C:\ScriptBASIC\examples\o2>scriba DLLcSpec2.sb
DLLC SPEC / DEMO / TESTS:

MyLib 1
ole32 2
ReturnQuadQV 12
Lapsed time Secs: 0.025151

raw:
name          C:/ScriptBASIC/modules/DLLCtestDLL.dll
metatype      1
handle        3014656
library       0
par count     0
par bytes     0
stack release 0

Params/Members
Return:

raw: stringbuf stdcall i=(c*buf, i bufsize)
name          stringbuf
metatype      2
handle        3030928
library       1
par count     2
par bytes     8
stack release 0

Params/Members
1  0    c
2  4    I
Return: I

raw: rectangle (i left,i top, i right, i bottom)
name          rectangle
metatype      3
handle        0
library       0
par count     4
par bytes     16
stack release 0

Params/Members
1  0    I
2  4    I
3  8    I
4  12   I
Return:

raw: rectangle (i left,i top, i right, i bottom)
name          rectangle
metatype      3
handle        0
library       0
par count     4
par bytes     16
stack release 0

Params/Members
1  0    I
2  4    I
3  8    I
4  12   I
Return:

Length of rect variables record: (16+4*2) 48
rect left    (10) 10
rect top     (20) 20
rect right   (30) 30
rect bottom  (40) 40
rect right (33) 33

greeting from stringbffuf procedure / DLLtestDLL

84
2.500000
Rectangle Area: 390
bstring handle: 6054164
This was an OLE/Bstring
bstring handle 6054164
This was an OLE/Bstring  (original bstring is automatically freed)

new bstring: handle=6054164
dispose bstring: handle=0

Wide string (6 to 12) 12
ascii string (12 to 6) 6
abcdef

32
GUID:
{96749377-3391-11D2-9EE3-00C04F797396}
{6C44DF74-72B9-4992-A1EC-EF996E0422D4}

pRect left    (100) 100
pRect top     (200) 200
pRect right   (300) 300
pRect bottom  (400) 400

DIRECT QUADS
0x00000004 0x00000005
Return QuadQ: 5,4
Return QuadQ: 5,4
Return QuadQ: 6,3
Return QuadQV: 6,3
Return QuadQV: 6,3


C:\ScriptBASIC\examples\o2>

« Last Edit: September 30, 2017, 12:59:28 AM by John »

Charles Pegge

  • Author
  • *****
  • Posts: 3266
    • Oxygen Basic
Re: DLLC Development
« Reply #3 on: September 27, 2017, 03:17:07 AM »
Hi John,

It is possible to create an oxygen dependant dllc.dll but you will need to provide the location of oxygen.dll in oxygen.cfg, alongside your scripts. However, it only saves about 12k of binary and there is no operational advantage.

oxygen.cfg
Code: [Select]
c:\scriptbasic\modules\oxygen.dll

re: making a generic dllc as an foreign-function-interface for other scripting languages. They are all different and I can't see a useful way of abstracting the code. Most of DLLC is customised ScriptBasic module interface calls.

John

  • Hero Member
  • *****
  • Posts: 2793
Re: DLLC Development
« Reply #4 on: September 27, 2017, 07:45:16 AM »
I was hoping you might find some value in Dave's VB6 COM/OLE interface with OxygenBasic.

You have made a huge investment of your time exposing Script BASIC's API. I have only scratched the surface of its feature set. I think O2 and SB play very well together.
« Last Edit: September 28, 2017, 09:47:45 AM by John »

John

  • Hero Member
  • *****
  • Posts: 2793
Re: DLLC Development - SAPI
« Reply #5 on: October 01, 2017, 11:45:13 PM »
This is a COM SAPI speech example using DLLC.

Code: Script BASIC
  1. 'SAPI - COM SPEECH
  2.  
  3. DECLARE SUB DLLC_FILE ALIAS "dllfile" LIB "DLLC"
  4. DECLARE SUB DLLC_PROC ALIAS "dllproc" LIB "DLLC"
  5. DECLARE SUB DLLC_GUID ALIAS "dllguid" LIB "DLLC"
  6. DECLARE SUB DLLC_METH ALIAS "dllmeth" LIB "DLLC"
  7. DECLARE SUB DLLC_RECO ALIAS "dllreco" LIB "DLLC"
  8. DECLARE SUB DLLC_WSTR ALIAS "dllwstr" LIB "DLLC"
  9. DECLARE SUB DLLC_CALL ALIAS "dllcall" LIB "DLLC"
  10. DECLARE SUB DLLC_ASTR ALIAS "dllastr" LIB "DLLC"
  11. DECLARE SUB DLLC_COBJ ALIAS "dllcobj" LIB "DLLC"
  12.  
  13. ole32 = DLLC_FILE("ole32.dll")
  14.  
  15. CoInitialize     = DLLC_PROC(ole32, "CoInitialize (i)")
  16. CoUninitialize   = DLLC_PROC(ole32, "CoUninitialize (i)")
  17. CoCreateInstance = DLLC_PROC(ole32, "CoCreateInstance i=(t*ObjGuid ,i pUnkOuter,i context, t*IspGuid, i*Iface)" )
  18.  
  19. VoiceObjGuid = DLLC_GUID("96749377-3391-11D2-9EE3-00C04F797396")
  20. ISpVoiceGuid = DLLC_GUID("6C44DF74-72B9-4992-A1EC-EF996E0422D4")
  21. Context      = 7
  22. pUnkOuter    = 0
  23. Voice        = 0
  24. Release      = DLLC_METH( 2, "Release i=()")
  25. Speak        = DLLC_METH(20, "Speak i=(z*pwcs,i flags,i pulstreamno)")
  26. WaitUntilDone= DLLC_METH(32, "WaitUntilDone i=(i)")
  27. PRINT DLLC_RECO(speak)
  28. Text         = DLLC_WSTR("Thank You Charles Pegge!\0")
  29. hr = 0
  30. DLLC_CALL(CoInitialize, 0)
  31. hr = DLLC_CALL(CoCreateInstance, VoiceObjGuid, pUnkouter, Context, ISpVoiceGuid, Voice)
  32. IF (hr = 0) THEN
  33.   PRINT "connected to voice\n\n"
  34.   PRINT DLLC_ASTR(Text) & "\n\n"
  35.   DLLC_COBJ(Voice, Speak, Text, 0, 0)
  36.   DLLC_COBJ(Voice, WaitUntilDone, 0xFFFFFFFF)
  37.   DLLC_COBJ(Voice, Release)
  38. ELSE
  39.   PRINT "SAPI Error " & FORMAT("%x", hr) & "\n\n"
  40. END IF
  41. DLLC_CALL(CoUninitialize)
  42.  
  43. DLLC_FILE
  44.  


C:\ScriptBASIC\examples\o2>scriba sapi.sb
raw: Speak i=(z*pwcs,i flags,i pulstreamno)
name          Speak
metatype      4
handle        80
library       0
par count     3
par bytes     12
stack release 0

Params/Members
1  0    z
2  4    I
3  8    I
Return: I
connected to voice

Thank You Charles Pegge!


C:\ScriptBASIC\examples\o2>


Here is the Script BASIC COM extension module version of the above example.

Code: Script BASIC
  1. IMPORT COM.sbi
  2.  
  3. obj = COM::CreateObject("SAPI.SpVoice")
  4. COM::CallByName(obj, "speak", VbMethod, "Thank You Dave!")
  5. COM::ReleaseObject(obj)
  6.  

« Last Edit: October 02, 2017, 09:21:02 PM by John »

John

  • Hero Member
  • *****
  • Posts: 2793
Re: DLLC Development - Date/Time
« Reply #6 on: October 08, 2017, 08:42:17 PM »
I noticed a COleDateTime and ColeDateTimeSpan example done by Josť Roca and thought I would see if I could reproduce the API calls with DLLC. Script BASIC already has a great date / time library so I used that instead to show like functionality.

Code: FreeBasic
  1. '#CONSOLE ON
  2. #define UNICODE
  3. #include once "Afx/COleDateTime.inc"
  4. USING Afx
  5.  
  6. ' // Create an instance of the COleDateTime class
  7. DIM cdt AS COleDateTime = ColeDateTime(2017, 10, 8, 12, 5, 30)   ' // 8 Octiber 2017, 12 hour, 5 minute, ad 30 second
  8. print cdt.GetYear, cdt.GetMonth, cdt.GetDay, cdt.GetHour, cdt.GetMinute, cdt.GetSecond
  9. print cdt.GetDayOfWeek, cdt.GetDayOfYear
  10. print cdt.Format
  11.  
  12. ' // Add a time span
  13. DIM ts AS COleDateTimeSpan = ColeDateTimeSpan(3, 1, 5, 12)   ' // 3 days, 1 hour, 5 min, and 12 sec
  14. cdt += ts
  15. print cdt.GetDayOfWeek, cdt.GetDayOfYear
  16.  
  17. ' // Display the date
  18. print cdt.Format
  19. print cdt.Format("%A, %B %d, %Y")
  20.    
  21. PRINT
  22. PRINT "Press any key..."
  23. SLEEP
  24.  

Code: Script BASIC
  1. ' Script BASIC Date/Time/Span
  2.  
  3. MINUTE_VALUE = 60
  4. HOUR_VALUE = 3600
  5. DAY_VALUE = 86400
  6.  
  7. ' cdt = TIMEVALUE(2017, 10, 8, 12, 5, 30)
  8. cdt = NOW
  9.  
  10. PRINT YEAR(cdt),"\t",MONTH(cdt),"\t",DAY(cdt),"\t",HOUR(cdt),"\t",MINUTE(cdt),"\t",SEC(cdt),"\n"
  11. PRINT WEEKDAY(cdt),"\t",FORMATDATE("WDN",cdt),"\t",FORMATDATE("WEEKDAY-NAME",cdt),"\t",YEARDAY(cdt),"\n"
  12. PRINT "Local: ",FORMATDATE("*MONTH-NAME* 0D, YEAR 0h:0m:0s pm", cdt),"\n"
  13. PRINT "  GMT: ",FORMATDATE("MON DD, YEAR 0h:0m:0s pm", LOCALTIMETOGMTIME(cdt)),"\n"
  14.  
  15. ' 3 days, 1 hour, 5 min, and 12 sec
  16. ts = cdt + DAY_VALUE * 3 + HOUR_VALUE + MINUTE_VALUE * 5 + 12
  17.  
  18. PRINT " Span: ",FORMATDATE("0M/0D/YEAR 0h:0m:0s pm", ts),"\n"
  19.  


jrs@jrs-laptop:~/sb/examples/test$ time scriba datetime.sb
2017   10   9   1   55   45
1   Mon   Monday   281
Local: October 09, 2017 01:55:45 am
  GMT: Oct 9, 2017 08:55:45 am
 Span: 10/12/2017 03:00:57 am

real   0m0.007s
user   0m0.004s
sys   0m0.000s
jrs@jrs-laptop:~/sb/examples/test$


Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\John>cd /scriptbasic/examples/test

C:\ScriptBASIC\examples\test>scriba datetime.sb
2017    10      9       21      33      2
1       Mon     Monday  281
Local: October 09, 2017 09:33:02 pm
  GMT: Oct 10, 2017 04:33:02 am
 Span: 10/12/2017 10:38:14 pm

C:\ScriptBASIC\examples\test>




Quote from: Josť Roca
Because the time64 C functions aren't available in msvcrt.dll, wich is limited to 32 bits, limiting the handling of dates from midnight, January 1, 1970, to 23:59:59 January 18, 2038, UTC,

Using a TIMEVALUE of 2040, Script BASIC returns the following. :-\ The error message seems wrong but 2048 probably overflowed and is being seen as a negative based value.

(0): error &H31:The time is not valid, cannot be earlier than January 1, 1970. 00:00

« Last Edit: October 09, 2017, 09:03:04 PM by John »

Charles Pegge

  • Author
  • *****
  • Posts: 3266
    • Oxygen Basic
Re: DLLC Development
« Reply #7 on: October 10, 2017, 03:04:26 AM »
Hi John,

I have very little experience with COM and had nothing to do with VBscript, VisualBasic, ActiveX, OCX,  or .NET. To me, this is a very deep rabbit hole with quite a few deprecations and dead-ends. So I am very cautious about getting involved with it without further knowledge of how this stuff is used independently of  Microsoft's development environment. (the Windows 10 SDK is a humungous 5 gigabytes)

Nonetheless I would like to take low-level COM support a bit further, looking at DirectX as a model. I have already done some fine tuning to Oxygen, while investigating Josť's port of DirectX9.

There is hope for indie language developers: MS is creating an new API called Windows Runtime which has .NET functionality but supports low-level access for c++


John

  • Hero Member
  • *****
  • Posts: 2793
Re: DLLC Development
« Reply #8 on: October 10, 2017, 10:15:18 AM »
Quote
Nonetheless I would like to take low-level COM support a bit further, looking at DirectX as a model. I have already done some fine tuning to Oxygen, while investigating Josť's port of DirectX9.

That is great news Charles. I feel Dave's VB6/COM/OLE extension module will handle the high level COM interfaces targeted at Microsoft Office and other main stream (QuickBooks Desktop) like interfaces.


John

  • Hero Member
  • *****
  • Posts: 2793
Re: DLLC Development
« Reply #9 on: October 12, 2017, 10:25:54 PM »
It seems rather easy to use .NET components with COM. Here is a C# example using the .NET Date Picker and made COM aware.

Creating COM Objects with Visual Basic.NET



Code: Script BASIC
  1. import com.inc
  2.  
  3. cs = CreateObject("Sample.Sample")
  4. d = CallByName(cs, "GetDate")
  5. print "User Selected date: ", d
  6.  


C:\sb22_32\sbvb-2>scriba cs_date.sb
User Selected date: 10/15/2017
C:\sb22_32\sbvb-2>


Hard to believe it has been over 3 years since Dave originally wrote the example. I miss Dave a lot.
« Last Edit: October 16, 2017, 02:33:21 PM by John »

John

  • Hero Member
  • *****
  • Posts: 2793
Re: DLLC Development
« Reply #10 on: October 14, 2017, 11:32:21 PM »
One of my most favorite features of Script BASIC is its array (matrix) functionality. You don't have to define or dimension anything and there are no practical limits on indices. (associative, indexed or a combination of both)

Code: Script BASIC
  1. ' Test  Associative Array by Index
  2.  
  3. obj{"Name"}{"Value"} = undef
  4. obj{"Name"}{"Product"} = "ALL"
  5. obj{"Name"}{"Required"} = TRUE
  6. obj{"ID"}{"Value"} = undef
  7. obj{"ID"}{"Product"} = "SOME"
  8. obj{"ID"}{"Required"} = FALSE
  9.  
  10. this{"Extension"}{"Value"} = "Default"
  11. this{"Extension"}{"Product"} = "FEW"
  12. this{"Extension"}{"Required"} = "MAYBE"
  13.  
  14. obj{"Version"} = this{"Extension"}
  15.  
  16. FOR o = 0 TO UBOUND(obj) STEP 2
  17.   PRINT obj[o],"\n"
  18.   FOR p = 0 TO UBOUND(obj[o + 1]) STEP 2
  19.     PRINT obj[o + 1, p]," - ",obj[o + 1, p + 1],"\n"
  20.   NEXT
  21. NEXT
  22.  
  23. PRINT "-------------------------------","\n"
  24.  
  25. PRINT obj[0],"\n"
  26. PRINT obj[1,0]," - ",obj[1,1],"\n"
  27. PRINT obj[1,2]," - ",obj[1,3],"\n"
  28. PRINT obj[1,4]," - ",obj[1,5],"\n"
  29. PRINT obj[2],"\n"
  30. PRINT obj[3,0]," - ",obj[3,1],"\n"
  31. PRINT obj[3,2]," - ",obj[3,3],"\n"
  32. PRINT obj[3,4]," - ",obj[3,5],"\n"
  33. PRINT obj[4],"\n"
  34. PRINT obj[5,0]," - ",obj[5,1],"\n"
  35. PRINT obj[5,2]," - ",obj[5,3],"\n"
  36. PRINT obj[5,4]," - ",obj[5,5],"\n"
  37.  
  38.  
  39. PRINT "-------------------------------","\n"
  40.  
  41. PRINT obj[2],"\n"
  42. FOR z = 0 TO UBOUND(obj{"ID"}) STEP 2
  43.   PRINT obj{"ID"}[z]," - ",obj{"ID"}[z + 1],"\n"
  44. NEXT
  45.  


Name
Value - undef
Product - ALL
Required - -1
ID
Value - undef
Product - SOME
Required - 0
Version
Value - Default
Product - FEW
Required - MAYBE
-------------------------------
Name
Value - undef
Product - ALL
Required - -1
ID
Value - undef
Product - SOME
Required - 0
Version
Value - Default
Product - FEW
Required - MAYBE
-------------------------------
ID
Value - undef
Product - SOME
Required - 0