aboutsummaryrefslogtreecommitdiff
path: root/CPP/Windows/ResourceString.cpp
diff options
context:
space:
mode:
authorIgor Pavlov <87184205+ip7z@users.noreply.github.com>2021-12-27 00:00:00 +0000
committerIgor Pavlov <87184205+ip7z@users.noreply.github.com>2022-03-18 15:35:13 +0500
commitf19f813537c7aea1c20749c914e756b54a9c3cf5 (patch)
tree816ba62ca7c0fa19f2eb46d9e9d6f7dd7c3a744d /CPP/Windows/ResourceString.cpp
parent98e06a519b63b81986abe76d28887f6984a7732b (diff)
download7zip-21.07.tar.gz
7zip-21.07.tar.bz2
7zip-21.07.zip
'21.07'21.07
Diffstat (limited to 'CPP/Windows/ResourceString.cpp')
-rw-r--r--CPP/Windows/ResourceString.cpp103
1 files changed, 103 insertions, 0 deletions
diff --git a/CPP/Windows/ResourceString.cpp b/CPP/Windows/ResourceString.cpp
new file mode 100644
index 0000000..ae8182e
--- /dev/null
+++ b/CPP/Windows/ResourceString.cpp
@@ -0,0 +1,103 @@
1// Windows/ResourceString.cpp
2
3#include "StdAfx.h"
4
5#ifndef _UNICODE
6#include "../Common/StringConvert.h"
7#endif
8
9#include "ResourceString.h"
10
11extern HINSTANCE g_hInstance;
12#ifndef _UNICODE
13extern bool g_IsNT;
14#endif
15
16namespace NWindows {
17
18#ifndef _UNICODE
19
20static CSysString MyLoadStringA(HINSTANCE hInstance, UINT resourceID)
21{
22 CSysString s;
23 int size = 128;
24 int len;
25 do
26 {
27 size <<= 1;
28 len = ::LoadString(hInstance, resourceID, s.GetBuf((unsigned)size - 1), size);
29 }
30 while (size - len <= 1);
31 s.ReleaseBuf_CalcLen((unsigned)len);
32 return s;
33}
34
35#endif
36
37static const int kStartSize = 256;
38
39static void MyLoadString2(HINSTANCE hInstance, UINT resourceID, UString &s)
40{
41 int size = kStartSize;
42 int len;
43 do
44 {
45 size <<= 1;
46 len = ::LoadStringW(hInstance, resourceID, s.GetBuf((unsigned)size - 1), size);
47 }
48 while (size - len <= 1);
49 s.ReleaseBuf_CalcLen((unsigned)len);
50}
51
52// NT4 doesn't support LoadStringW(,,, 0) to get pointer to resource string. So we don't use it.
53
54UString MyLoadString(UINT resourceID)
55{
56 #ifndef _UNICODE
57 if (!g_IsNT)
58 return GetUnicodeString(MyLoadStringA(g_hInstance, resourceID));
59 else
60 #endif
61 {
62 {
63 wchar_t s[kStartSize];
64 s[0] = 0;
65 int len = ::LoadStringW(g_hInstance, resourceID, s, kStartSize);
66 if (kStartSize - len > 1)
67 return s;
68 }
69 UString dest;
70 MyLoadString2(g_hInstance, resourceID, dest);
71 return dest;
72 }
73}
74
75void MyLoadString(HINSTANCE hInstance, UINT resourceID, UString &dest)
76{
77 dest.Empty();
78 #ifndef _UNICODE
79 if (!g_IsNT)
80 MultiByteToUnicodeString2(dest, MyLoadStringA(hInstance, resourceID));
81 else
82 #endif
83 {
84 {
85 wchar_t s[kStartSize];
86 s[0] = 0;
87 int len = ::LoadStringW(hInstance, resourceID, s, kStartSize);
88 if (kStartSize - len > 1)
89 {
90 dest = s;
91 return;
92 }
93 }
94 MyLoadString2(hInstance, resourceID, dest);
95 }
96}
97
98void MyLoadString(UINT resourceID, UString &dest)
99{
100 MyLoadString(g_hInstance, resourceID, dest);
101}
102
103}