zoukankan      html  css  js  c++  java
  • [Windows Api 学习] Error Handling Functions

    BOOL WINAPI FlashWindowEx(
      __in          PFLASHWINFO pfwi
    );

    DWORD WINAPI FormatMessage(
      __in          DWORD dwFlags,
      __in          LPCVOID lpSource,
      __in          DWORD dwMessageId,
      __in          DWORD dwLanguageId,
      __out         LPTSTR lpBuffer,
      __in          DWORD nSize,
      __in          va_list* Arguments
    );

    eg. Retrieving the Last-Error Code

    #include <windows.h>
    #include <strsafe.h>
    
    void ErrorExit(LPTSTR lpszFunction) 
    { 
        // Retrieve the system error message for the last-error code
    
        LPVOID lpMsgBuf;
        LPVOID lpDisplayBuf;
        DWORD dw = GetLastError(); 
    
        FormatMessage(
            FORMAT_MESSAGE_ALLOCATE_BUFFER | 
            FORMAT_MESSAGE_FROM_SYSTEM |
            FORMAT_MESSAGE_IGNORE_INSERTS,
            NULL,
            dw,
            MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
            (LPTSTR) &lpMsgBuf,
            0, NULL );
    
        // Display the error message and exit the process
    
        lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT, 
            (lstrlen((LPCTSTR)lpMsgBuf)+lstrlen((LPCTSTR)lpszFunction)+40)*sizeof(TCHAR)); 
        StringCchPrintf((LPTSTR)lpDisplayBuf, 
            LocalSize(lpDisplayBuf),
            TEXT("%s failed with error %d: %s"), 
            lpszFunction, dw, lpMsgBuf); 
        MessageBox(NULL, (LPCTSTR)lpDisplayBuf, TEXT("Error"), MB_OK); 
    
        LocalFree(lpMsgBuf);
        LocalFree(lpDisplayBuf);
        ExitProcess(dw); 
    }
    
    void main()
    {
        // Generate an error
    
        if(!GetProcessId(NULL))
            ErrorExit(TEXT("GetProcessId"));
    }
    

      

  • 相关阅读:
    转:深入 AngularUI Router
    angularJS $scope的$apply方法实现model刷新
    CSS 如何让 height:100%; 起作用
    【AngularJs】---$sce 输出Html
    angular 组件之间传值
    kendo Grid 列添加自定义模板
    关于“内控点”
    关于总结
    咏春
    一只老鼠夹
  • 原文地址:https://www.cnblogs.com/vlan99/p/3685975.html
Copyright © 2011-2022 走看看