Creer un raccourci

gagah1 Messages postés 509 Date d'inscription samedi 28 juin 2003 Statut Membre Dernière intervention 3 août 2010 - 1 déc. 2003 à 21:37
BruNews Messages postés 21041 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019 - 1 déc. 2003 à 23:54
Quelqu'un pourrait m'aider à créer un raccourci(sur le bureau) d'un fichier .exe à partir d'un petit code source???Merci.

5 réponses

BruNews Messages postés 21041 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019
1 déc. 2003 à 21:54
#include <windows.h>
#include <shlobj.h>

char *szappname = "Shortcut";

int __stdcall CreateShortcut(char* szflSrc, char* szLink, char *szTooltip)
{
IShellLink* psl;
HANDLE hheap;
WORD* pwsz;
IPersistFile* ppf;
int bOK;
char *c, *d;
if(CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
IID_IShellLink, (LPVOID*) &psl)) return 0; hheap GetProcessHeap(); bOK 0; if((pwsz (WORD*) HeapAlloc(hheap, 0, MAX_PATH*2)) 0) goto outPsl;
if(psl->QueryInterface(IID_IPersistFile, (LPVOID *) &ppf)) goto outHeap;
psl->SetPath(szflSrc); psl->SetDescription(szTooltip); d (char*) pwsz; c szflSrc;
while(*d = *c++) d++;
bOK = 0;
while((*d != '\\') && (d > (char*) pwsz)) d--;
if(d <= (char*) pwsz) goto outHeap;
*d = 0;
psl->SetWorkingDirectory((char*) pwsz);
if(MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, szLink, -1, pwsz, MAX_PATH)) bOK (ppf->Save(pwsz, TRUE) 0);
ppf->Release();
outHeap: HeapFree(hheap, 0, pwsz);
outPsl: psl->Release();
return bOK;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR, int)
{
if(CoInitialize(NULL)) return 0;
if(!CreateShortcut("D:\\Sfmg\\AccesSFMG.doc", "D:\\AccesSFMG.lnk", "UN TEST"))
MessageBox(NULL, "Shortcut raté", szappname, MB_ICONEXCLAMATION);
CoUninitialize();
return 0;
}

BruNews, ciao...
0
gagah1 Messages postés 509 Date d'inscription samedi 28 juin 2003 Statut Membre Dernière intervention 3 août 2010
1 déc. 2003 à 22:21
Merci BruNews!!!!
Si je comprends bien, szflSrc c'est le nom de fichier+chemin du fichier .exe en quelque sorte et szlink le nom de fichier du raccourci. Mais si je place le raccourci dans le bureau directement , le chemin est-il :"C:\\Documents and Settings\\All Users\\raccouci.Ink" ou comment??
0
BruNews Messages postés 21041 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019
1 déc. 2003 à 22:25
Le chemin des dossier personnels n'a rien de fixe, comme quasi tout le reste d'ailleurs.
Tu dois les lire ici:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
BruNews, ciao...
0
gagah1 Messages postés 509 Date d'inscription samedi 28 juin 2003 Statut Membre Dernière intervention 3 août 2010
1 déc. 2003 à 23:35
C'est trop compliqué pour moi.
J'ai essayé de compiler votre source sur dev-C++ mais il y a des tas d'erreurs de compilation que je ne comprends pas comme:
'com_interface' only supported with _fvtable_thunks ou
[warning] 'com_interface' attribute directive ignored...
Est-ce que vous pouvez m'aider encore???Merci.
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
BruNews Messages postés 21041 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019
1 déc. 2003 à 23:54
Desole mais le cpp est complet pour compiler tel quel sur tout Visual Studio de 5 a superieur. Je n'emploie que cela.
BruNews, ciao...
0
Rejoignez-nous