VB6.0开发,调用了DLL中的方法去获取两个字符串,但实际返回字符串的地址。
怎样从地址得到完整的字符串内容呢?方法如下,核心是oleaut32.dll中的SysAllocStringByteLen方法:
Private Declare Function SysAllocStringByteLen Lib "oleaut32.dll" (ByVal m_pBase As Long, ByVal l As Long) As String
Private Declare Function lstrlen Lib "kernel32.dll" Alias "lstrlenA" (ByVal lpString As Long) As Long' This function is called from the dll
' pName and pId is address, a number
Public Function callBack(ByVal pName As Long, ByVal pId As Long) As LongMsgBox ("pName is: " & pName & " " & "pId is: " & pId)Dim deviceName As String
Dim deviceId As String
deviceName = SysAllocStringByteLen(pName, lstrlen(pName))
deviceId = SysAllocStringByteLen(pId, lstrlen(pId))MsgBox (deviceName & " " & deviceId)End Function
效果:
参考:如何在VB中从long指定的地址中获取字符串-腾讯云开发者社区-腾讯云