• GetLastError()数字_转换为_文字


    1、具体参数 可参看 http://blog.csdn.net/hongweigg/article/details/6821536 或 其它文章 或 MSDN

    2、VC6 测试代码:

    #include <stdio.h>
    #include <windows.h>
    
    void main()
    {
        LPTSTR lpMsgBuf;
        //DWORD nErrno = GetLastError();
        DWORD nErrno = 10060;
        FormatMessage(
            FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
            NULL,
            nErrno,
            MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
            (LPTSTR)&lpMsgBuf,
            0,
            NULL);
    
        MessageBox(NULL, (LPCTSTR)lpMsgBuf, TEXT("NamedPipe Error"), MB_OK | MB_ICONINFORMATION );
        LocalFree(lpMsgBuf);
    }

    3、Delphi7 测试代码:

    //#define MAKELANGID(p, s)       ((((WORD  )(s)) << 10) | (WORD  )(p))
    function MAKELANGID(_p, _s :word) :DWORD;
    begin
      Result := (_s shl 10) or (_p);
    end;
    
    //#define LANG_NEUTRAL                     0x00
    //#define SUBLANG_DEFAULT                  0x01    // user default
    {$O-}
    function ErrorNo2Str(_dwErrNo :DWORD):string;
    const
      LANG_NEUTRAL = $0;
      SUBLANG_DEFAULT = $01;
    var pcMsgBuf :PChar;
        buf :array[0..255] of Char;
    begin
    //function FormatMessage(
    //  dwFlags: DWORD;
    //  lpSource: Pointer;
    //  dwMessageId: DWORD;
    //  dwLanguageId: DWORD;
    //  lpBuffer: PChar;
    //  nSize: DWORD;
    //  Arguments: Pointer): DWORD; stdcall;
    //{$EXTERNALSYM FormatMessage}
    {
      Windows.FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER or FORMAT_MESSAGE_FROM_SYSTEM or FORMAT_MESSAGE_IGNORE_INSERTS,
        0,
        _dwErrNo,
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
        pcMsgBuf,
        0,
        nil);
    
        Result := pcMsgBuf;
        
        LocalFree(DWORD(pcMsgBuf));
    }
    // *** 使用上面的参数方式(OS帮我们申请字符串缓冲区空间),始终不对...连断点都下不了...于是,使用下面的方式... ***
      ZeroMemory(@buf[0], Length(buf));
      Windows.FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM or FORMAT_MESSAGE_IGNORE_INSERTS,
        0,
        _dwErrNo,     
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
        buf,
        Length(buf),
        nil);
    
      Result := buf;
    end;
    {$O+}
    
    procedure TForm1.Button1Click(Sender: TObject);
    var dwErrNo :DWORD;
        str :string;
    begin
      dwErrNo := 10060;
    
      str := ErrorNo2Str(dwErrNo);
      Memo1.Lines.Add(str);
    end;

    4、

    5、

  • 相关阅读:
    ggplot2|theme主题设置,详解绘图优化-“精雕细琢”-
    ggplot2|theme主题设置,详解绘图优化-“精雕细琢”
    阻抗设计01
    Geber文件,装配图,BOM表的输出
    c语言里面你不知道的break与switch,contiune的用法
    数据结构之链表学习01
    数据结构概念及连续存储数组的算法演示
    使用malloc和free函数进行内存动态分配
    浅谈结构体
    浅谈指针01
  • 原文地址:https://www.cnblogs.com/cppskill/p/6113315.html
Copyright © 2020-2023  润新知