xLeaves
18-07-2019, 00:22
I saw a sample code:
Function Exec_FBGFX_InKey() As BSTR
'----------------------------------------------------------------------------
' This function returns a OLE string
'----------------------------------------------------------------------------
Dim ParensPresent As Long
'---Check if open parens is present
ParensPresent = thinBasic_CheckOpenParens_Optional
Dim sBSTR As BSTR '---OLE string will be used to return value to thinCore
'---String will be used internally and than assigned to OLE string
'---Here we use a dynamic string (that in reality is a pointer to a structure whose first
'---4 bytes are a pointer to a buffer containing the real string
'---In this case also a fized ZString would be ok
Dim InKeyString As String
'---Check inkey
InKeyString = InKey
'---If something was returned than we use it to allocate an OLE string
If InKeyString <> "" then
'---Allocate OLE string using specific APIs. In this case we use SysAllocStringByteLen
'---in order to also pass an initial value string
sBSTR = SysAllocStringByteLen( InKeyString, Len(InKeyString) )
End If
'---If initial parens was present that final one is mandatory
If ParensPresent = TB_TRUE Then thinBasic_CheckCloseParens_Mandatory
Function = sBSTR
End Function
Here sBSTR returns directly to ThinBasic, I am not sure if ThinBasic is a saved copy of the string or a pointer provided by the plugin, and how the data is eventually released to avoid memory leaks.
Function Exec_FBGFX_InKey() As BSTR
'----------------------------------------------------------------------------
' This function returns a OLE string
'----------------------------------------------------------------------------
Dim ParensPresent As Long
'---Check if open parens is present
ParensPresent = thinBasic_CheckOpenParens_Optional
Dim sBSTR As BSTR '---OLE string will be used to return value to thinCore
'---String will be used internally and than assigned to OLE string
'---Here we use a dynamic string (that in reality is a pointer to a structure whose first
'---4 bytes are a pointer to a buffer containing the real string
'---In this case also a fized ZString would be ok
Dim InKeyString As String
'---Check inkey
InKeyString = InKey
'---If something was returned than we use it to allocate an OLE string
If InKeyString <> "" then
'---Allocate OLE string using specific APIs. In this case we use SysAllocStringByteLen
'---in order to also pass an initial value string
sBSTR = SysAllocStringByteLen( InKeyString, Len(InKeyString) )
End If
'---If initial parens was present that final one is mandatory
If ParensPresent = TB_TRUE Then thinBasic_CheckCloseParens_Mandatory
Function = sBSTR
End Function
Here sBSTR returns directly to ThinBasic, I am not sure if ThinBasic is a saved copy of the string or a pointer provided by the plugin, and how the data is eventually released to avoid memory leaks.