helperfunctions code

#include <Windows.h>

#include <wchar.h>

#define ERRORSIZE 40


HANDLE hOut;

BOOL result;

DWORD error;

BOOL debug = FALSE;


void Write(LPCWSTR sz)

{

if (NULL == hOut) {

hOut = GetStdHandle(STD_OUTPUT_HANDLE);

}//if

DWORD length = (DWORD)wcslen(sz);

DWORD written = 0;


WriteConsoleW(hOut, sz, length, &written, NULL);

}


void WriteLine(LPCWSTR sz)

{

Write(sz);

Write(L"\n");

}


void Error(LPCWSTR szFunctionName)

{

if (debug) {

error = GetLastError();

if (0 != error) {

WCHAR szError[ERRORSIZE];

_ultow_s(error, szError, sizeof(szError) / sizeof(WCHAR), 10);

Write(szFunctionName);

Write(L" error ");

WriteLine(szError);

error = 0;

}//if

}//if

}

 © Andrew Brehm 2016