|
#pragma once
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#pragma unmanaged
#include <strsafe.h>
#pragma managed
// Link lib
#pragma comment(lib, "strsafe.lib")
#define UNREF(x) x;
typedef unsigned int uint;
typedef unsigned char uchar;
namespace WPFOpenGLLib
{
class Helper
{
public:
//
// Taken from MSDN
//
static 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) / sizeof(TCHAR),
TEXT("%s failed with error %d: %s"),
lpszFunction, dw, lpMsgBuf);
::MessageBox(NULL, (LPCTSTR)lpDisplayBuf, TEXT("Error"), MB_OK);
LocalFree(lpMsgBuf);
LocalFree(lpDisplayBuf);
ExitProcess(dw);
}
};
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Chris lives in Munich, Germany and tries to study Physics.
Alongside, he works as a self-employed software consultant on projects from various fields.
Unfortunately, he loved software ever since he started with C++, and his addiction has become a lot worse since the introduction of .NET 2.0.
In his spare time, he tries to go sailing, drink some nice single malt whisky and, in very rare cases, he also sleeps.
You can reach him at ChrisNOSPAM at emphess.net or via
his blog emphess.net.