Skip to content

Commit

Permalink
Windows: Dumped the now unused Wide/Ansi string conversion utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Jun 19, 2014
1 parent d40ee04 commit a215b5c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 68 deletions.
32 changes: 5 additions & 27 deletions doomsday/client/include/windows/dd_winit.h
@@ -1,7 +1,7 @@
/** @file dd_winit.h
/** @file dd_winit.h Win32 Initialization.
*
* @authors Copyright © 2003-2013 Jaakko Kernen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2013 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2003-2014 Jaakko Kernen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2014 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
Expand All @@ -17,10 +17,6 @@
* http://www.gnu.org/licenses</small>
*/

/**
* Win32 Initialization.
*/

#ifndef LIBDENG_WINIT_H
#define LIBDENG_WINIT_H

Expand All @@ -33,17 +29,9 @@
extern "C" {
#endif

//#define MAINWCLASS "DoomsdayMainWClass"

typedef struct {
HINSTANCE hInstance;
/*
#ifdef UNICODE
LPCWSTR className;
#else
LPCSTR className;
#endif
*/

/// @c true = We are using a custom user dir specified on the command line.
BOOL usingUserDir;

Expand All @@ -55,17 +43,7 @@ extern application_t app;
dd_bool DD_Win32_Init(void);
void DD_Shutdown(void);

const char* DD_Win32_GetLastErrorMessage(void);

#ifdef UNICODE
LPCWSTR ToWideString(const char* str);
LPCSTR ToAnsiString(const wchar_t* wstr);
# define WIN_STRING(s) (ToWideString(s))
# define UTF_STRING(ws) (ToAnsiString(ws))
#else
# define WIN_STRING(s) (s)
# define UTF_STRING(ws) (ws)
#endif
char const *DD_Win32_GetLastErrorMessage(void);

#ifdef __cplusplus
} // extern "C"
Expand Down
43 changes: 2 additions & 41 deletions doomsday/client/src/windows/dd_winit.cpp
Expand Up @@ -51,41 +51,6 @@

application_t app;

#ifdef UNICODE
static LPWSTR convBuf;
static LPSTR utf8ConvBuf;
#endif

#ifdef UNICODE
LPCWSTR ToWideString(char const *str)
{
// Determine the length of the output string.
int wideChars = MultiByteToWideChar(CP_UTF8, 0, str, -1, 0, 0);

// Allocate the right amount of memory.
int bufSize = wideChars * sizeof(wchar_t) + 1;
convBuf = (LPWSTR) M_Realloc(convBuf, bufSize);
std::memset(convBuf, 0, bufSize);

MultiByteToWideChar(CP_ACP, 0, str, -1, convBuf, wideChars);

return convBuf;
}

LPCSTR ToAnsiString(wchar_t const *wstr)
{
// Determine how much memory is needed for the output string.
int utfBytes = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, 0, 0, 0, 0);

// Allocate the right amount of memory.
utf8ConvBuf = (LPSTR) M_Realloc(utf8ConvBuf, utfBytes);

WideCharToMultiByte(CP_UTF8, 0, wstr, -1, utf8ConvBuf, utfBytes, 0, 0);

return utf8ConvBuf;
}
#endif

/**
* @note GetLastError() should only be called when we *know* an error was thrown.
* The result of calling this any other time is undefined.
Expand Down Expand Up @@ -114,8 +79,9 @@ char const *DD_Win32_GetLastErrorMessage()
dd_snprintf(buffer, currentBufferSize, "#%-5d: ", (int)dw);

// Continue splitting as long as there are parts.
{ char* part, *cursor = (char*)lpMsgBuf;
char *part, *cursor = (char *)lpMsgBuf;
while(*(part = M_StrTok(&cursor, "\n")))
{
strcat(buffer, part);
}

Expand Down Expand Up @@ -233,11 +199,6 @@ void DD_Shutdown()
Plug_UnloadAll();
Library_Shutdown();

#ifdef UNICODE
M_Free(convBuf); convBuf = 0;
M_Free(utf8ConvBuf); utf8ConvBuf = 0;
#endif

// No more use of COM beyond, this point.
CoUninitialize();

Expand Down

0 comments on commit a215b5c

Please sign in to comment.