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
| void AddInStartupGrp(LPSTR szShortcutFile,LPSTR szSourcePath) {
HRESULT hres;
IShellLink *psl;
TCHAR LNKpath[MAX_PATH]; //char LNKpath[MAX_PATH];
WCHAR wsLNKpath[MAX_PATH];
LPITEMIDLIST pItemIDlist;
CoInitialize(NULL); // Initialisez COM
SHGetSpecialFolderLocation(NULL,CSIDL_STARTUP,&pItemIDlist);
//SHGetPathFromIDList(pItemIDlist,LNKpath);
if (FAILED(SHGetFolderPath(NULL,CSIDL_STARTUP,NULL,0,LNKpath))) {
exit; // échec
}
strcat(LNKpath,"\\");
strcat(LNKpath,szShortcutFile);
strcat(LNKpath,".ink");
//free(pItemIDlist); // Libère la variable
hres = CoCreateInstance(&CLSID_ShellLink,NULL,CLSCTX_INPROC_SERVER,&IID_IShellLink,(void **)&psl);
if (SUCCEEDED (hres)) {
IPersistFile *ppf;
hres = psl->lpVtbl->QueryInterface(psl,&IID_IPersistFile,(void **)&ppf);
if (SUCCEEDED (hres)){
hres = psl->lpVtbl->SetPath(psl,szSourcePath);
printf("1 - %s - %s\n",hres,psl);
MultiByteToWideChar(CP_ACP,0,LNKpath,-1,wsLNKpath,MAX_PATH);
hres = ppf->lpVtbl->Save(ppf,wsLNKpath,FALSE);
ppf->lpVtbl->Release(ppf);
printf("2 - %s - %s\n",hres,ppf);
system("Pause");
} else {
system("echo Erreur 1");
system("Pause");
}
} else {
system("echo Erreur 2");
system("Pause");
}
psl->lpVtbl->Release (psl);
CoUninitialize(); // Liberer COM
} |
Partager