-
Notifications
You must be signed in to change notification settings - Fork 1
/
def.cpp
179 lines (153 loc) · 3.62 KB
/
def.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#include "stdafx.h"
#include "Intshcut.h"
unsigned long long tinymt64state[2] = { 'T', 'M' };
float sz2f(const char * const sz)
{
WCHAR wzT[256];
MultiByteToWideChar(CP_ACP, 0, sz, -1, wzT, 256);
CComVariant var = wzT;
if (SUCCEEDED(VariantChangeType(&var, &var, 0, VT_R4)))
{
const float result = V_R4(&var);
VariantClear(&var);
return result;
}
return 0.0f;
}
void f2sz(const float f, char * const sz)
{
CComVariant var = f;
if (SUCCEEDED(VariantChangeType(&var, &var, 0, VT_BSTR)))
{
WCHAR * const wzT = V_BSTR(&var);
WideCharToMultiByte(CP_ACP, 0, wzT, -1, sz, 256, NULL, NULL);
VariantClear(&var);
}
else
sprintf_s(sz, 255, "0.0");
}
void WideStrCopy(const WCHAR *wzin, WCHAR *wzout)
{
while (*wzin) { *wzout++ = *wzin++; }
*wzout = 0;
}
void WideStrNCopy(const WCHAR *wzin, WCHAR *wzout, const DWORD wzoutMaxLen)
{
DWORD i = 0;
while (*wzin && (i < wzoutMaxLen - 1)) { *wzout++ = *wzin++; i++; }
*wzout = 0;
}
void WideStrCat(const WCHAR *wzin, WCHAR *wzout)
{
wzout += lstrlenW(wzout);
while (*wzin) { *wzout++ = *wzin++; }
*wzout = 0;
}
int WideStrCmp(const WCHAR *wz1, const WCHAR *wz2)
{
while (*wz1 != L'\0')
{
if (*wz1 != *wz2)
{
if (*wz1 > *wz2)
{
return 1; // If *wz2 == 0, then wz1 will return as higher, which is correct
}
else if (*wz1 < *wz2)
{
return -1;
}
}
wz1++;
wz2++;
}
if (*wz2 != L'\0')
{
return -1; // wz2 is longer - and therefore higher
}
return 0;
}
int WzSzStrCmp(const WCHAR *wz1, const char *sz2)
{
while (*wz1 != L'\0')
{
if (*wz1++ != *sz2++)
{
return 1;
}
}
if (*sz2 != L'\0')
{
return 1;
}
return 0;
}
int WzSzStrnCmp(const WCHAR *wz1, const char *sz2, const int count)
{
int i = 0;
while (*wz1 != L'\0' && i < count)
{
if (*wz1++ != *sz2++)
{
return 1;
}
i++;
}
if (*sz2 != L'\0')
{
return 1;
}
return 0;
}
LocalString::LocalString(const int resid)
{
if (resid > 0)
/*const int cchar =*/ LoadString(g_hinst, resid, m_szbuffer, 256);
else
m_szbuffer[0] = 0;
}
LocalStringW::LocalStringW(const int resid)
{
if (resid > 0)
LoadStringW(g_hinst, resid, str, 256);
else
str[0] = 0;
}
WCHAR *MakeWide(const char * const sz)
{
const int len = lstrlen(sz);
WCHAR * const wzT = new WCHAR[len + 1];
MultiByteToWideChar(CP_ACP, 0, sz, -1, wzT, len + 1);
return wzT;
}
char *MakeChar(const WCHAR * const wz)
{
const int len = lstrlenW(wz);
char * const szT = new char[len + 1];
WideCharToMultiByte(CP_ACP, 0, wz, -1, szT, len + 1, NULL, NULL);
return szT;
}
HRESULT OpenURL(char *szURL)
{
IUniformResourceLocator* pURL;
HRESULT hres = CoCreateInstance(CLSID_InternetShortcut, NULL, CLSCTX_INPROC_SERVER, IID_IUniformResourceLocator, (void**)&pURL);
if (!SUCCEEDED(hres))
{
return hres;
}
hres = pURL->SetURL(szURL, IURL_SETURL_FL_GUESS_PROTOCOL);
if (!SUCCEEDED(hres))
{
pURL->Release();
return hres;
}
//Open the URL by calling InvokeCommand
URLINVOKECOMMANDINFO ivci;
ivci.dwcbSize = sizeof(URLINVOKECOMMANDINFO);
ivci.dwFlags = IURL_INVOKECOMMAND_FL_ALLOW_UI;
ivci.hwndParent = g_pvp->m_hwnd;
ivci.pcszVerb = "open";
hres = pURL->InvokeCommand(&ivci);
pURL->Release();
return (hres);
}