-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShortCutClass.cpp
66 lines (59 loc) · 1.65 KB
/
ShortCutClass.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
//---------------------------------------------------------------------------
#define VCL_FULL
#include <vcl.h>
#pragma hdrstop
#define NO_WIN32_LEAN_AND_MEAN
#include <Shlobj.h>
#include <io.h>
#include "ShortCutClass.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
CShortCut::CShortCut(AnsiString FName)
{
FileName=FName;
}
CShortCut::~CShortCut()
{
}
bool CShortCut::Create(void)
{
bool results;
HRESULT hres;
IShellLink *psl;
IPersistFile *ppf;
wchar_t wsz[MAX_PATH];
CoInitialize(NULL);
hres = CoCreateInstance(CLSID_ShellLink, NULL,
CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)&psl);
results=false;
if (SUCCEEDED(hres))
{
psl->SetPath(LinkFile.c_str());
psl->SetWorkingDirectory(LinkPath.c_str());
psl->SetDescription(LinkDescription.c_str());
hres = psl->QueryInterface(IID_IPersistFile, (void**)&ppf);
if (SUCCEEDED(hres))
{
MultiByteToWideChar(CP_ACP, 0, FileName.c_str(), -1,
wsz, MAX_PATH);
hres = ppf->Save(wsz, true);
ppf->Release();
results=true;
}
psl->Release();
}
CoUninitialize();
return results;
}
bool CShortCut::Delete(void)
{
return DeleteFile(FileName);
}
AnsiString GetSystemPath(int nFolder)
{
char StartPath[MAXPATH];
LPITEMIDLIST pidl;
SHGetSpecialFolderLocation(Application->Handle, nFolder , &pidl); //CSIDL_STARTUP, CSIDL_STARTMENU, CSIDL_PROGRAMS
SHGetPathFromIDList(pidl, StartPath);
return AnsiString(StartPath);
}