SkHRESULT.cpp revision b29c883fb46ac6099440d82ac57b86d25386daed
1b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com/*
2b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com * Copyright 2011 Google Inc.
3b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com *
4b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com * Use of this source code is governed by a BSD-style license that can be
5b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com * found in the LICENSE file.
6b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com */
7b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com
8b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com#include "SkTypes.h"
9b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com
10b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com#include "SKHRESULT.h"
11b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com
12b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.comvoid SkTraceHR(const char* file, unsigned long line,
13b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com               HRESULT hr, const char* msg) {
14b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com    if (NULL != msg) SkDEBUGF(("%s\n", msg));
15b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com    SkDEBUGF(("%s(%lu) : error 0x%x: ", file, line, hr));
16b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com
17b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com    LPSTR errorText = NULL;
18b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com    FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
19b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com                   FORMAT_MESSAGE_FROM_SYSTEM |
20b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com                   FORMAT_MESSAGE_IGNORE_INSERTS,
21b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com                   NULL,
22b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com                   hr,
23b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com                   MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
24b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com                   (LPSTR) &errorText,
25b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com                   0,
26b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com                   NULL
27b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com    );
28b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com
29b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com    if (NULL == errorText) {
30b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com        SkDEBUGF(("<unknown>\n"));
31b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com    } else {
32b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com        SkDEBUGF((errorText));
33b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com        LocalFree(errorText);
34b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com        errorText = NULL;
35b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com    }
36b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com}
37