src/core/windows/SDL_windows.c
author Philipp Wiesemann
Thu, 30 May 2013 12:23:36 +0200
changeset 7242 96f4133dfafa
parent 7037 3fedf1f25b94
child 7828 1451063c8ecd
child 8460 f483e8bdae3c
permissions -rw-r--r--
Added deactivated loading of SDL2_net to Java file.
slouken@5090
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@6885
     3
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
slouken@5090
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@5090
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@5090
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@5090
    20
*/
slouken@5090
    21
#include "SDL_config.h"
slouken@5090
    22
slouken@6044
    23
#ifdef __WIN32__
slouken@6044
    24
slouken@5090
    25
#include "SDL_error.h"
slouken@5090
    26
#include "SDL_windows.h"
icculus@6990
    27
#include "SDL_assert.h"
slouken@5090
    28
icculus@5598
    29
#include <objbase.h>  /* for CoInitialize/CoUninitialize */
icculus@5591
    30
slouken@5090
    31
/* Sets an error message based on GetLastError() */
icculus@7037
    32
int
slouken@5090
    33
WIN_SetError(const char *prefix)
slouken@5090
    34
{
slouken@5090
    35
    TCHAR buffer[1024];
slouken@5090
    36
    char *message;
slouken@5090
    37
    FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0,
slouken@5090
    38
                  buffer, SDL_arraysize(buffer), NULL);
slouken@5090
    39
    message = WIN_StringToUTF8(buffer);
slouken@5090
    40
    SDL_SetError("%s%s%s", prefix ? prefix : "", prefix ? ": " : "", message);
slouken@5090
    41
    SDL_free(message);
icculus@7037
    42
    return -1;
slouken@5090
    43
}
slouken@5090
    44
icculus@5591
    45
HRESULT
icculus@5591
    46
WIN_CoInitialize(void)
icculus@5591
    47
{
icculus@6031
    48
    const HRESULT hr = CoInitialize(NULL);
icculus@6031
    49
icculus@5591
    50
    /* S_FALSE means success, but someone else already initialized. */
icculus@5591
    51
    /* You still need to call CoUninitialize in this case! */
icculus@6031
    52
    if (hr == S_FALSE) {
icculus@5591
    53
        return S_OK;
icculus@5591
    54
    }
icculus@5591
    55
icculus@5591
    56
    return hr;
icculus@5591
    57
}
icculus@5591
    58
icculus@5591
    59
void
icculus@5591
    60
WIN_CoUninitialize(void)
icculus@5591
    61
{
icculus@5591
    62
    CoUninitialize();
icculus@5591
    63
}
icculus@5591
    64
slouken@6044
    65
#endif /* __WIN32__ */
slouken@6044
    66
slouken@5090
    67
/* vi: set ts=4 sw=4 expandtab: */