A
Ai
Hi I'm passing this work sheet ID from a XLL (using Excel4(xlSheetId,
&xRet, 1, &xRef) to VBA and trying to use it as a sheet id. Problem
is I always get garbage value behind the string value. Any advise?
Below is my VBA codes:
Private Declare Sub CopyMemory Lib "kernel32" Alias
"RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As
Long)
Private Declare Function lstrlenW Lib "kernel32" (ByVal lpString As
Long) As Long
Private Function StringFromPointer(lngPtr As Long) As String
Dim l As Long
Dim s As String
Dim strTemp As String
Dim lngLen As Long
If lngPtr Then
lngLen = lstrlenW(lngPtr) * 2
If lngLen Then
strTemp = Space(lngLen)
CopyMemory ByVal strTemp, ByVal lngPtr, lngLen
StringFromPointer = Replace(strTemp, Chr(0), "")
End If
End If
End Function
Sub XLLCallBack(ByVal workSheetId As Long)
Debug.Print "workSheetId: " & workSheetId
Dim sheetName As String
sheetName = StringFromPointer(workSheetId)
....
End Sub
&xRet, 1, &xRef) to VBA and trying to use it as a sheet id. Problem
is I always get garbage value behind the string value. Any advise?
Below is my VBA codes:
Private Declare Sub CopyMemory Lib "kernel32" Alias
"RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As
Long)
Private Declare Function lstrlenW Lib "kernel32" (ByVal lpString As
Long) As Long
Private Function StringFromPointer(lngPtr As Long) As String
Dim l As Long
Dim s As String
Dim strTemp As String
Dim lngLen As Long
If lngPtr Then
lngLen = lstrlenW(lngPtr) * 2
If lngLen Then
strTemp = Space(lngLen)
CopyMemory ByVal strTemp, ByVal lngPtr, lngLen
StringFromPointer = Replace(strTemp, Chr(0), "")
End If
End If
End Function
Sub XLLCallBack(ByVal workSheetId As Long)
Debug.Print "workSheetId: " & workSheetId
Dim sheetName As String
sheetName = StringFromPointer(workSheetId)
....
End Sub