zoukankan      html  css  js  c++  java
  • 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、

  • 相关阅读:
    jmeter接口测试3-正则表达式提取器的使用
    Sublime中Markdown的安装与使用
    python使用you-get模块下载视频
    python BeautifulSoup模块的简要介绍
    python Requests模块的简要介绍
    mongodb基本操作的学习
    python中的常用方法
    网盘的选择,百度网盘、google drive 还是 Dropbox
    python_爬虫一之爬取糗事百科上的段子
    pycharm的使用破解和Anaconda的使用
  • 原文地址:https://www.cnblogs.com/cppskill/p/6113315.html
Copyright © 2011-2022 走看看