Click to See Complete Forum and Search --> : Long To String
Lev FatMan
May 14th, 2001, 04:07 AM
Hello,
Lets say I recieve from somewhere a long number that I know for sure its a pointer to a string. How can I read the string in VB?
I know its possible.
FatMan
cksiow
May 14th, 2001, 04:34 AM
use the following API
Declare Function lstrcpy Lib "kernel32.dll" Alias "lstrcpyA" (lpString1 As Any, lpString2 As Any) As Long
lpString1 is the destination string, a byte array variable, maybe can be string variable, try it yourself
lpString2 is the pointer, a long variable
alternatively, try RtlMovememory.
HTH
cksiow
http://vblib.virtualave.net - share our codes
Clearcode
May 14th, 2001, 04:35 AM
You can use the foillowing code snippet....
API Declaration
private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Dest as Any, Src as Any, byval cb&)
Use:
public Function StringFromPointer(lpString as Long, lMaxLength as Long) as string
Dim sRet as string
Dim lRet as Long
'\\ Pre-initialise the return string...
sRet = Space$(lMaxLength)
CopyMemory byval sRet, byval lpString, byval len(sRet)
If Err.LastDllError = 0 then
If InStr(sRet, Chr$(0)) > 0 then
sRet = Left$(sRet, InStr(sRet, Chr$(0)) - 1)
End If
End If
StringFromPointer = sRet
End Function
-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.