-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathotherapi.cpp
84 lines (72 loc) · 2.08 KB
/
otherapi.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
#include "otherapi.h"
// 检查一个文件是否存在
BOOL IsFileExist(LPCTSTR lpFileName)
{
WIN32_FIND_DATA fd = {0};
HANDLE hFind = FindFirstFile(lpFileName, &fd);
if (hFind != INVALID_HANDLE_VALUE) {
FindClose(hFind);
}
return ((hFind != INVALID_HANDLE_VALUE) && !(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY));
}
// 获得文件大小
size_t get_fileSize(const char* filename)
{
FILE* pfile = fopen(filename, "rb");
fseek(pfile, 0 , SEEK_END);
size_t size = ftell(pfile);
fclose(pfile);
return size;
}
// 功能 获得当前路径
char* GetAppDir(char* szPath)
{
char* ret = szPath;
GetModuleFileName(NULL, szPath, MAX_PATH); // 得到当前执行文件的文件名(包含路径)
*(strrchr(szPath , '\\')) = '\0'; // 删除文件名,只留下目录
return ret;
}
// 得到全路径文件的文件名
const char* GetFileBaseName(const char* szPath)
{
const char* ret = szPath + strlen(szPath);
while ((*ret != '\\') && (ret != (szPath - 1))) // 得到文件名
ret--;
ret++;
return ret;
}
// 内存匹配函数memfind
char* memfind(const char* buf, const char* tofind, size_t len)
{
size_t findlen = strlen(tofind);
if (findlen > len) {
return ((char*)NULL);
}
if (len < 1) {
return ((char*)buf);
}
{
const char* bufend = &buf[len - findlen + 1];
const char* c = buf;
for (; c < bufend; c++) {
if (*c == *tofind) { // first letter matches
if (!memcmp(c + 1, tofind + 1, findlen - 1)) { // found
return ((char*)c);
}
}
}
}
return ((char*)NULL);
}
// 路径转宽字节
wchar_t* charToWCHAR(wchar_t* wch, const char* czs)
{
MultiByteToWideChar(CP_ACP, 0, czs, -1, wch, MAX_PATH); // czs 转换到宽字节wch
return wch;
}
char* WCHARTochar(char* czs , const wchar_t* wch)
{
WideCharToMultiByte(CP_ACP, 0, wch, -1, czs, MAX_PATH , NULL, NULL);
return czs;
}