Archived

This topic is now archived and is closed to further replies.

doctorsixstring

Creating shortcuts

Recommended Posts

That''s not what I meant. I want to actually create a *.lnk file (a windows shortcut file) in a specified directory from within my code. I don''t want to simply launch an executable.

I have looked at IShellLink, and it looks like it might be the only available tool. O therwise I might have to right an entire .lnk file out myself as a binary file.

If anyone has any info on making this task easier, please let me know.

-Mike

Share this post


Link to post
Share on other sites
From CPT:

  
int CPT_SystemLinkSpawn(const char *Link, const char *File) {
HRESULT Result;
IShellLink *PSL;
IPersistFile *PPF;
char *LinkExt;
WORD WSZ[CPT_SYSTEM_PATHMAX];

CoInitialize(NULL);

Result = CoCreateInstance(&CLSID_ShellLink, NULL,
CLSCTX_INPROC_SERVER, &IID_IShellLink, (void **) &PSL);

if(SUCCEEDED(Result)) {
PSL->lpVtbl->SetPath(PSL,File);
PSL->lpVtbl->SetDescription(PSL,"");

Result = PSL->lpVtbl->QueryInterface(PSL, &IID_IPersistFile, (void **) &PPF);
if(SUCCEEDED(Result)) {
LinkExt = (char *) malloc(sizeof(char) * (strlen(Link) + 5));
if(LinkExt == NULL) {
PSL->lpVtbl->Release(PSL);
CoUninitialize();
return -3;
}

strcpy(LinkExt,Link);
strcat(LinkExt,"
.lnk");

MultiByteToWideChar(CP_ACP, 0, LinkExt, -1, WSZ, CPT_SYSTEM_PATHMAX);

Result = PPF->lpVtbl->Save(PPF, WSZ, TRUE);
PPF->lpVtbl->Release(PPF);

free(LinkExt);
} else return -2;
PSL->lpVtbl->Release(PSL);
} else return -1;

CoUninitialize();

return 0;
}



Share this post


Link to post
Share on other sites