-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhelper.cpp
56 lines (44 loc) · 1.45 KB
/
helper.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
#include "helper.h"
LPSTR charToLPSTR(const char* str) {
if (str == nullptr) {
return nullptr;
}
size_t len = strlen(str);
LPSTR lpstr = (LPSTR)LocalAlloc(LPTR, len + 1);
if (lpstr != nullptr) {
strcpy_s(lpstr, len + 1, str);
}
return lpstr;
}
LPCWSTR charToLPCWSTR(const char* charString) {
// Calculate the size needed for the wide string buffer
int size_needed = MultiByteToWideChar(CP_ACP, 0, charString, -1, NULL, 0);
// Allocate memory for the wide string buffer
static wchar_t wideString[256];
if (size_needed > sizeof(wideString) / sizeof(wideString[0])) {
// Handle buffer size exceeded case
return NULL;
}
// Perform the conversion
MultiByteToWideChar(CP_ACP, 0, charString, -1, wideString, size_needed);
return wideString;
}
LPWSTR charToLPWSTR(const char* charString) {
// Calculate the size needed for the wide string buffer
int size_needed = MultiByteToWideChar(CP_ACP, 0, charString, -1, NULL, 0);
// Allocate memory for the wide string buffer
static wchar_t wideString[256]; // Adjust buffer size as needed
if (size_needed > sizeof(wideString) / sizeof(wideString[0])) {
// Handle buffer size exceeded case
return NULL;
}
// Perform the conversion
MultiByteToWideChar(CP_ACP, 0, charString, -1, wideString, size_needed);
return wideString;
}
void setConsoleColor(int colorCode) {
#ifdef _WIN32
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, colorCode); // 设置颜色
#endif
}