DeviceDescriptor: eliminate obsolete NMEAOut kludge
[xcsoar.git] / src / ResourceLoader.cpp
blobc56c5933e700aef41dd13a41dd2d3ad57474540f
1 /*
2 Copyright_License {
4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "ResourceLoader.hpp"
26 #include <assert.h>
28 #ifdef WIN32
30 #include <windows.h>
32 static HINSTANCE ResourceLoaderInstance;
34 void
35 ResourceLoader::Init(HINSTANCE hInstance)
37 assert(ResourceLoaderInstance == NULL);
39 ResourceLoaderInstance = hInstance;
42 #else /* !WIN32 */
44 #include "resource_data.h"
46 #include <string.h>
48 #endif /* !WIN32 */
50 ResourceLoader::Data
51 ResourceLoader::Load(const TCHAR *name, const TCHAR *type)
53 #ifdef WIN32
54 assert(ResourceLoaderInstance != NULL);
56 HRSRC resource = ::FindResource(ResourceLoaderInstance, name, type);
57 if (resource == NULL)
58 return Data((const void *)NULL, 0);
60 DWORD size = ::SizeofResource(ResourceLoaderInstance, resource);
61 if (size == 0)
62 return Data((const void *)NULL, 0);
64 HGLOBAL handle = ::LoadResource(ResourceLoaderInstance, resource);
65 if (handle == NULL)
66 return Data((const void *)NULL, 0);
68 LPVOID data = LockResource(handle);
69 if (data == NULL)
70 return Data((const void *)NULL, 0);
72 return std::pair<const void *, size_t>(data, size);
73 #else
75 for (unsigned i = 0; named_resources[i].data != NULL; ++i)
76 if (_tcscmp(named_resources[i].name, name) == 0)
77 return Data(named_resources[i].data, named_resources[i].size);
79 return Data((const void *)NULL, 0);
80 #endif
83 ResourceLoader::Data
84 ResourceLoader::Load(unsigned id)
86 #ifdef WIN32
87 return Load(MAKEINTRESOURCE(id), RT_BITMAP);
88 #else
90 for (unsigned i = 0; numeric_resources[i].data != NULL; ++i)
91 if (numeric_resources[i].id == id)
92 return Data(numeric_resources[i].data, numeric_resources[i].size);
94 return Data((const void *)NULL, 0);
95 #endif
98 #ifdef WIN32
99 HBITMAP
100 ResourceLoader::LoadBitmap2(unsigned id)
102 return ::LoadBitmap(ResourceLoaderInstance, MAKEINTRESOURCE(id));
104 #endif
106 #ifdef HAVE_AYGSHELL_DLL
107 #include "OS/AYGShellDLL.hpp"
109 HBITMAP
110 ResourceLoader::SHLoadImageResource(unsigned id)
112 const AYGShellDLL ayg_shell_dll;
113 return ayg_shell_dll.SHLoadImageResource(ResourceLoaderInstance, id);
115 #endif