-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathYsetting.cpp
More file actions
68 lines (47 loc) · 2.01 KB
/
Copy pathYsetting.cpp
File metadata and controls
68 lines (47 loc) · 2.01 KB
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
#pragma comment(lib, "Ole32.lib")
#pragma comment(lib, "Shell32.lib")
#include <windows.h>
#include <shlobj.h>
#include <string>
bool CreateLink(const std::wstring& exePath, const std::wstring& startInPath, const std::wstring& iconPath, const std::wstring& lnkPath) {
HRESULT hr = CoInitialize(NULL);
if (FAILED(hr)) return false;
IShellLinkW* psl = nullptr;
hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLinkW, (LPVOID*)&psl);
if (SUCCEEDED(hr)) {
IPersistFile* ppf = nullptr;
psl->SetPath(exePath.c_str());
psl->SetWorkingDirectory(startInPath.c_str());
psl->SetIconLocation(iconPath.c_str(), 0);
hr = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf);
if (SUCCEEDED(hr)) {
hr = ppf->Save(lnkPath.c_str(), TRUE);
ppf->Release();
}
psl->Release();
}
CoUninitialize();
return SUCCEEDED(hr);
}
int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) {
wchar_t currentExePath[MAX_PATH];
GetModuleFileNameW(NULL, currentExePath, MAX_PATH);
std::wstring exeStr(currentExePath);
size_t lastSlash = exeStr.rfind(L'\\');
if (lastSlash == std::wstring::npos) {
return 0;
}
std::wstring baseDir = exeStr.substr(0, lastSlash);
std::wstring gameExePath = baseDir + L"\\Ygame\\Ygame.exe";
std::wstring iconPath = baseDir + L"\\icon\\Y.ico";
wchar_t desktopPath[MAX_PATH];
if (SHGetFolderPathW(NULL, CSIDL_DESKTOPDIRECTORY, NULL, 0, desktopPath) == S_OK) {
std::wstring lnkPath = std::wstring(desktopPath) + L"\\Ygame.lnk";
if (CreateLink(gameExePath, baseDir, iconPath, lnkPath)) {
MessageBoxW(NULL, L"바탕화면에 Ygame 바로가기가 생성됐습니다!", L"완료", MB_OK | MB_ICONINFORMATION);
return 0;
}
}
MessageBoxW(NULL, L"바로가기 생성에 실패했습니다.", L"오류", MB_OK | MB_ICONERROR);
return 0;
}