Oxygen Basic
Programming => Problems & Solutions => Topic started by: Aurel on October 02, 2018, 10:10:29 AM
-
Charles
when i looking into Jose post i want try one VB example about thematicand here is code:
'Get String from Pointer
! lstrlenA Lib "kernel32.dll" (ByVal lpString As Long) As Long
! PutMem4 Lib "msvbvm60.dll" (ByVal Addr As Long, ByVal NewVal As Long) As Long
! SysAllocString Lib "oleaut32.dll" (Optional ByVal pszStrPtr As Long) As Long
! SysAllocStringByteLen Lib "oleaut32.dll"(Optional ByVal pszStrPtr As Long, Optional ByVal Length As Long) As String
! SysReAllocString Lib "oleaut32.dll" (ByVal pBSTR As Long, Optional ByVal pszStrPtr As Long) As Long
declare function GetStrFromPtrA(ByVal Ptr As Long) As String
'test
'Returns a copy of a null-terminated ANSI string (LPSTR/LPCSTR) from the given pointer
Function GetStrFromPtrA(ByVal Ptr As Long) As String
Function = SysAllocStringByteLen( Ptr, lstrlenA(Ptr))
End Function
string s = GetStrFromPtrA(100)
and compiler complain that variable ptr is not defined because is in local scope
or maybe something else ?
just asking...
-
Hi Aurel,
Ptr is a reserved word, so changing to aPtr solves the problem
'Get String from Pointer
! lstrlenA Lib "kernel32.dll" (ByVal lpString As Long) As Long
! PutMem4 Lib "msvbvm60.dll" (ByVal Addr As Long, ByVal NewVal As Long) As Long
! SysAllocString Lib "oleaut32.dll" (Optional ByVal pszStrPtr As Long) As Long
! SysAllocStringByteLen Lib "oleaut32.dll"(Optional ByVal pszStrPtr As Long, Optional ByVal Length As Long) As String
! SysReAllocString Lib "oleaut32.dll" (ByVal pBSTR As Long, Optional ByVal pszStrPtr As Long) As Long
declare function GetStrFromPtrA(ByVal aPtr As Long) As String
'test
'Returns a copy of a null-terminated ANSI string (LPSTR/LPCSTR) from the given pointer
Function GetStrFromPtrA(ByVal aPtr As Long) As String
Function = SysAllocStringByteLen( aPtr, lstrlenA(aPtr))
End Function
-
And using a true pointer, instead of 100, will also help :)