diff options
Diffstat (limited to 'src/dutil/gdiputil.cpp')
| -rw-r--r-- | src/dutil/gdiputil.cpp | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/src/dutil/gdiputil.cpp b/src/dutil/gdiputil.cpp index aef6178f..b5a0087c 100644 --- a/src/dutil/gdiputil.cpp +++ b/src/dutil/gdiputil.cpp | |||
| @@ -4,6 +4,21 @@ | |||
| 4 | 4 | ||
| 5 | using namespace Gdiplus; | 5 | using namespace Gdiplus; |
| 6 | 6 | ||
| 7 | |||
| 8 | // Exit macros | ||
| 9 | #define GdipExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_GDIPUTIL, x, s, __VA_ARGS__) | ||
| 10 | #define GdipExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_GDIPUTIL, x, s, __VA_ARGS__) | ||
| 11 | #define GdipExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_GDIPUTIL, x, s, __VA_ARGS__) | ||
| 12 | #define GdipExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_GDIPUTIL, x, s, __VA_ARGS__) | ||
| 13 | #define GdipExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_GDIPUTIL, x, s, __VA_ARGS__) | ||
| 14 | #define GdipExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_GDIPUTIL, x, s, __VA_ARGS__) | ||
| 15 | #define GdipExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_GDIPUTIL, p, x, e, s, __VA_ARGS__) | ||
| 16 | #define GdipExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_GDIPUTIL, p, x, s, __VA_ARGS__) | ||
| 17 | #define GdipExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_GDIPUTIL, p, x, e, s, __VA_ARGS__) | ||
| 18 | #define GdipExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_GDIPUTIL, p, x, s, __VA_ARGS__) | ||
| 19 | #define GdipExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_GDIPUTIL, e, x, s, __VA_ARGS__) | ||
| 20 | #define GdipExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_GDIPUTIL, g, x, s, __VA_ARGS__) | ||
| 21 | |||
| 7 | /******************************************************************** | 22 | /******************************************************************** |
| 8 | GdipInitialize - initializes GDI+. | 23 | GdipInitialize - initializes GDI+. |
| 9 | 24 | ||
| @@ -22,7 +37,7 @@ extern "C" HRESULT DAPI GdipInitialize( | |||
| 22 | Status status = Ok; | 37 | Status status = Ok; |
| 23 | 38 | ||
| 24 | status = GdiplusStartup(pToken, pInput, pOutput); | 39 | status = GdiplusStartup(pToken, pInput, pOutput); |
| 25 | ExitOnGdipFailure(status, hr, "Failed to initialize GDI+."); | 40 | GdipExitOnGdipFailure(status, hr, "Failed to initialize GDI+."); |
| 26 | 41 | ||
| 27 | LExit: | 42 | LExit: |
| 28 | return hr; | 43 | return hr; |
| @@ -59,15 +74,15 @@ extern "C" HRESULT DAPI GdipBitmapFromResource( | |||
| 59 | Status gs = Ok; | 74 | Status gs = Ok; |
| 60 | 75 | ||
| 61 | hr = ResReadData(hinst, szId, &pvData, &cbData); | 76 | hr = ResReadData(hinst, szId, &pvData, &cbData); |
| 62 | ExitOnFailure(hr, "Failed to load GDI+ bitmap from resource."); | 77 | GdipExitOnFailure(hr, "Failed to load GDI+ bitmap from resource."); |
| 63 | 78 | ||
| 64 | // Have to copy the fixed resource data into moveable (heap) memory | 79 | // Have to copy the fixed resource data into moveable (heap) memory |
| 65 | // since that's what GDI+ expects. | 80 | // since that's what GDI+ expects. |
| 66 | hGlobal = ::GlobalAlloc(GMEM_MOVEABLE, cbData); | 81 | hGlobal = ::GlobalAlloc(GMEM_MOVEABLE, cbData); |
| 67 | ExitOnNullWithLastError(hGlobal, hr, "Failed to allocate global memory."); | 82 | GdipExitOnNullWithLastError(hGlobal, hr, "Failed to allocate global memory."); |
| 68 | 83 | ||
| 69 | pv = ::GlobalLock(hGlobal); | 84 | pv = ::GlobalLock(hGlobal); |
| 70 | ExitOnNullWithLastError(pv, hr, "Failed to lock global memory."); | 85 | GdipExitOnNullWithLastError(pv, hr, "Failed to lock global memory."); |
| 71 | 86 | ||
| 72 | memcpy(pv, pvData, cbData); | 87 | memcpy(pv, pvData, cbData); |
| 73 | 88 | ||
| @@ -75,15 +90,15 @@ extern "C" HRESULT DAPI GdipBitmapFromResource( | |||
| 75 | pv = NULL; | 90 | pv = NULL; |
| 76 | 91 | ||
| 77 | hr = ::CreateStreamOnHGlobal(hGlobal, TRUE, &pStream); | 92 | hr = ::CreateStreamOnHGlobal(hGlobal, TRUE, &pStream); |
| 78 | ExitOnFailure(hr, "Failed to allocate stream from global memory."); | 93 | GdipExitOnFailure(hr, "Failed to allocate stream from global memory."); |
| 79 | 94 | ||
| 80 | hGlobal = NULL; // we gave the global memory to the stream object so it will close it | 95 | hGlobal = NULL; // we gave the global memory to the stream object so it will close it |
| 81 | 96 | ||
| 82 | pBitmap = Bitmap::FromStream(pStream); | 97 | pBitmap = Bitmap::FromStream(pStream); |
| 83 | ExitOnNull(pBitmap, hr, E_OUTOFMEMORY, "Failed to allocate bitmap from stream."); | 98 | GdipExitOnNull(pBitmap, hr, E_OUTOFMEMORY, "Failed to allocate bitmap from stream."); |
| 84 | 99 | ||
| 85 | gs = pBitmap->GetLastStatus(); | 100 | gs = pBitmap->GetLastStatus(); |
| 86 | ExitOnGdipFailure(gs, hr, "Failed to load bitmap from stream."); | 101 | GdipExitOnGdipFailure(gs, hr, "Failed to load bitmap from stream."); |
| 87 | 102 | ||
| 88 | *ppBitmap = pBitmap; | 103 | *ppBitmap = pBitmap; |
| 89 | pBitmap = NULL; | 104 | pBitmap = NULL; |
| @@ -123,13 +138,13 @@ extern "C" HRESULT DAPI GdipBitmapFromFile( | |||
| 123 | Bitmap *pBitmap = NULL; | 138 | Bitmap *pBitmap = NULL; |
| 124 | Status gs = Ok; | 139 | Status gs = Ok; |
| 125 | 140 | ||
| 126 | ExitOnNull(ppBitmap, hr, E_INVALIDARG, "Invalid null wzFileName"); | 141 | GdipExitOnNull(ppBitmap, hr, E_INVALIDARG, "Invalid null wzFileName"); |
| 127 | 142 | ||
| 128 | pBitmap = Bitmap::FromFile(wzFileName); | 143 | pBitmap = Bitmap::FromFile(wzFileName); |
| 129 | ExitOnNull(pBitmap, hr, E_OUTOFMEMORY, "Failed to allocate bitmap from file."); | 144 | GdipExitOnNull(pBitmap, hr, E_OUTOFMEMORY, "Failed to allocate bitmap from file."); |
| 130 | 145 | ||
| 131 | gs = pBitmap->GetLastStatus(); | 146 | gs = pBitmap->GetLastStatus(); |
| 132 | ExitOnGdipFailure(gs, hr, "Failed to load bitmap from file: %ls", wzFileName); | 147 | GdipExitOnGdipFailure(gs, hr, "Failed to load bitmap from file: %ls", wzFileName); |
| 133 | 148 | ||
| 134 | *ppBitmap = pBitmap; | 149 | *ppBitmap = pBitmap; |
| 135 | pBitmap = NULL; | 150 | pBitmap = NULL; |
