'WinErrorMsg
'WinErrorMsg(GetLastError) '显示API错误
'显示指定Windows错误代码的文本
'显示为中文
Function WinErrorMsg (ByVal dError as DWord)  as String

    Dim pBuffer   as ZString Ptr 
    Dim ncbBuffer as DWord

    ncbBuffer = FormatMessageA (FORMAT_MESSAGE_ALLOCATE_BUFFER Or _
                               FORMAT_MESSAGE_FROM_SYSTEM Or _
                               FORMAT_MESSAGE_IGNORE_INSERTS, _
                               Null, _
                               dError, _
                               MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), _
                               Cast(any ptr, @pBuffer), _
                               0, _
                               ByVal Null)

    If pBuffer>0 And ncbBuffer>0 Then
        Function = *pBuffer
        LocalFree pBuffer
    End If

End Function