• Advertisement

Archived

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

Creating shortcuts

This topic is 5695 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
You can run programs from within you program using the ShellExecute or ShellExecuteEx API functions (although there may well be a better way).

Share this post


Link to post
Share on other sites
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
Thanks Null and Void. It took a while to get everything to work right, but I am now able to create a shortcut to a file with a given icon. Thanks!

-Mike

Share this post


Link to post
Share on other sites

  • Advertisement