ConvertLong


Description:
This function attempts a smart conversion of a Long into a string. It will not attempt to convert the long if it appears to not be a string, and just a normal number. This is useful for dereferencing the quasi pointer that the EnumResource functions return.
 
Code:
Option Explicit

Declare Function lstrcpy_long Lib "kernel32" Alias "lstrcpyA" _
   (ByVal lpString1 As String, ByVal lpString2 As Long) As Long

Declare Function lstrlen_long Lib "kernel32" Alias "lstrlenA" _
   (ByVal lpString As Long) As Long

Public Function ConvertLong(lpsz As Long) As String

    If lpsz > &HFFFF& Then
        ConvertLong = Space(lstrlen_long(lpsz))
        lstrcpy_long ConvertLong, lpsz
    Else
        ConvertLong = "0x" & Right(String(4, "0") & Hex(lpsz), 4)
    End If

End Function
 
Sample Usage:
 
Public Function EnumResourceNameProc(ByVal hMod As Long, _
   ByVal lpszType As Long, ByVal lpszName As Long, _
   ByVal lParam As Long) As Boolean

    Debug.Print ConvertLong(lpszName)

    EnumResourceNameProc = True

End Function