如何从VB中long指定的地址获取字符串 [英] How to get the string from an address specified by a long in VB

查看:28
本文介绍了如何从VB中long指定的地址获取字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 vba 中,有一个指向空终止字符串的 long 类型持有的地址,但我找不到从该地址获取字符串的方法:

In vba, There is an address held by a long type which points to a null-terminated string, but I can't find a way to get the string from this address:

long str_address = ...
string str = ?

你能解释一下吗?

推荐答案

我使用 CopyMemory 这种方式:

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Function lstrlenA Lib "kernel32" (ByVal lpString As Long) As Long

Private Function pvToString(ByVal lPtr As Long) As String
    If lPtr <> 0 Then
        pvToString = String(lstrlenA(lPtr), 0)
        Call CopyMemory(ByVal pvToString, ByVal lPtr, Len(pvToString))
    End If
End Function

这篇关于如何从VB中long指定的地址获取字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆