Creating File Links
Posted
by Michael Taupitz
on February 7th, 1999
Okay, the right book at the right time, and every problem can be solved...
The Solution I found under a small chapter about IShellLink. But not much Info, and so i tried it out.
CoInitialize(NULL); hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*) &psl;);
If it was successful, you can set Path, Description and so on. But to create the link in real (on Harddisk) we need IPersistFile
hres = psl->QueryInterface( IID_IPersistFile, (LPVOID *) &ppf;);
and save the File...
hres = ppf->Save(, TRUE);
Thats all.
So, if anybody need it complete:
// Creating a Link with IShellLink // strPathObj = Object with Path // strPathLink = Path where the Link will appear // strDesc = Link-Decription (the text under the Icon) // CoInitialize(NULL) wird vorausgesetzt !! HRESULT MyMainClass::CreateLink(const CString strPathObj,const CString strPathLink, const CString strDesc) { HRESULT hres; IShellLink* psl; CString strMyPath = strPathLink; hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*) &psl;); if (SUCCEEDED(hres)) { IPersistFile* ppf; psl->SetPath(strPathObj); psl->SetDescription(strDesc); hres = psl->QueryInterface( IID_IPersistFile, (LPVOID *) &ppf;); if (SUCCEEDED(hres)) { strMyPath += ".lnk"; // Important !!! WORD wsz[MAX_PATH]; MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, strMyPath, -1, wsz, MAX_PATH); hres = ppf->Save(wsz, TRUE); if (hres != S_OK ) MessageBox(NULL, "IPersistFile->Save() Error", "Error", MB_OK); ppf->Release(); } psl->Release(); } return hres; }Okay, lets take a look on the Function above : What you need to make the link is only to know where is the File for the Link, where you want to create the Link, and what a Name should appear under the Icon. The Path where comes in the Link must be added with the Name for the Link ( under the Icon) and needs (its Important) a .lnk extension.
C:\Now call the Function :\ .lnk
FileLink([Source-Path with File], [Destination-Path with an allowed Name and .lnk as Extension] (like C:\[Path]\[Name you want].lnk ]);
And if you would like to try a complete Sample you can download FileLinkDemo.zip (only Win NT4.0 tested) (19KB)
Date Posted: 10/5/98
Comments
Creating PIF's
Posted by Legacy on 10/16/2000 12:00amOriginally posted by: Amnon
Hi, Michael.
ReplyThank you very much for your article about creating links.
We need in our project create PIF's along with links. Is the're a way to do it ?
Amnon
Library problem
Posted by Legacy on 10/05/2000 12:00amOriginally posted by: Jesper Mattsson
I get "unresolved external symbol" on CoInitzialize() and CoCreateInstance() from the linker.
How do i make it find the right library?
ReplyProblems with handles! -> Memory overflow!
Posted by Legacy on 03/29/2000 12:00amOriginally posted by: Michael D.
I have encountered a problem in my coding concerning the creation of shortcuts using the given code. As i'm creating shortcuts from time to time on the desktop and in a folder during runtime of my source (NT-Service), i have discovered that the command
CoCreateInstance(...) and
psl->SetPath(Target)
envoke 3 handles in total.
Since my code is a service, which runs for days - not to mention weeks or months, i get a momory overflow due to tons of handles which my service produces.
Does someone know any solution to my problem or can give me a hint? I'd appriciate any help!
Thanks in advance
Michael
How to indicate position on the desktop when creating a shortcut!
Posted by Legacy on 03/26/2000 12:00amOriginally posted by: Eric Forget
The code work properly but can i indicate the position of the new shortcut when i created it on the desktop?
Eric
Replycreating internet shortcut
Posted by Legacy on 12/22/1999 12:00amOriginally posted by: Venu Vemula
easy way to setting up a icon for shortcut
Posted by Legacy on 12/18/1999 12:00amOriginally posted by: Marcos Mori de Siqueira
How can application get multifiles at the same time?
Posted by Legacy on 12/17/1999 12:00amOriginally posted by: HenryIII
HI,men
ReplyCould I ask you some qestions about VC++ programing?
In fact, I wanna get the work out that when draging
some files to my application, it can get these filenames
into string buffers. I know Winamp(MP3 player) can do
this. For examples, when you choose a lot of mp3 files
and press "ENTER", winamp will play them one by one
( Of course *.MP3 file should open with winamp )
Apparently, winamp get all of them. But some application
can get only one object file.
How can I do it?
Looking forward your suggestion.
I want to launch application as file is double clicked..!
Posted by Legacy on 07/08/1999 12:00amOriginally posted by: maroo
I want to launch application as file is double clicked
in window explorer(not browser).
How to make it??
ReplyNotes and Enhancements : CreateShortcut
Posted by Legacy on 11/17/1998 12:00amOriginally posted by: Firo