CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Long To String

  1. #1
    Join Date
    Feb 2001
    Location
    Israel
    Posts
    94

    Long To String

    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




  2. #2
    Join Date
    Apr 2000
    Posts
    737

    Re: Long To String

    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


  3. #3
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: Long To String

    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
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured