sancarn / stdVBA

VBA Standard Library - A Collection of libraries to form a common standard layer for modern VBA applications.
MIT License
294 stars 58 forks source link

`stdRuntimeJS` #80

Open sancarn opened 1 year ago

sancarn commented 1 year ago

Honestly this whole class needs a total rewrite. It was made when I was younger and more naive.



Chakracore.dll can't support JsValueToVariant ,so change to this:

'Run = helperJS2VB(R)
Run = JsValueToSTR(R)



Private Declare Function JsConvertValueToString Lib "Chakra.dll" (ByVal m_JsValue As Long, ByVal VARPTR_RESULstr As Long) As Long
Private Declare Function JsStringToPointer Lib "Chakra.dll" (ByVal m_JsValue As Long, stringValue As Long, stringLength As Long) As Long
Public Declare Function SysReAllocString Lib "oleaut32.dll" (ByVal pBSTR As Long, Optional ByVal pszStrPtr As Long) As Long

Public Function GetStrFromPtrw(ByVal Ptr As Long) As String
  'GOOD(ptr前面是4个字节的长度)
  SysReAllocString VarPtr(GetStrFromPtrw), Ptr
End Function

Function JsValueToSTR(m_JsValue As Long) As String
  Dim JsStringPtr As Long
  Dim VbStringPtr As Long
  Dim StringLen As Long
  Dim ret As Long
  ret = JsConvertValueToString(m_JsValue, VarPtr(JsStringPtr))
  ret = JsStringToPointer(JsStringPtr, VbStringPtr, StringLen)
  JsValueToSTR = GetStrFromPtrw(VbStringPtr)
End Function
```vb