|
-
Aug 14th, 2000, 03:17 PM
#1
Thread Starter
New Member
Hello. I'm trying to create a Dial-Up Networking shortcut
on the desktop using IShellLink, coding in VB6. I have the
C source to do this, but I don't know C at all. Can anyone
help? Thanks.
#include <windows.h>
#include <ole2.h>
#include <shlguid.h>
#include <shlobj.h>
// CreateLink - uses the shell's IShellLink and IPersistFile interfaces
// to create and store a shortcut to the specified object.
// Returns the result of calling the member functions of the interfaces.
// lpszPathObj - address of a buffer containing the path of the object
// lpszPathLink - address of a buffer containing the path where the
// shell link is to be stored
// lpszDesc - address of a buffer containing the description of the
// shell link
// lpszWorkingDirectory - where the application is run
// lpszArguments - command line arguments
HRESULT CreateShortcut(LPCSTR lpszPathObj, LPSTR lpszPathLink, LPSTR lpszDesc, LPSTR lpszWorkingDirectory,
LPSTR lpszArguments)
{
HRESULT hres;
IShellLink* psl;
CoInitialize(NULL);
// Get a pointer to the IShellLink interface.
hres = CoCreateInstance(&CLSID_ShellLink, NULL,
CLSCTX_INPROC_SERVER, &IID_IShellLink, &psl);
if (SUCCEEDED(hres))
{
IPersistFile* ppf;
// Set the path to the shortcut target, and add the
// description.
psl->lpVtbl->SetPath(psl, lpszPathObj);
psl->lpVtbl->SetDescription(psl, lpszDesc);
psl->lpVtbl->SetWorkingDirectory(psl, lpszWorkingDirectory);
psl->lpVtbl->SetArguments(psl, lpszArguments);
// Query IShellLink for the IPersistFile interface for saving the
// shortcut in persistent storage.
hres = psl->lpVtbl->QueryInterface(psl, &IID_IPersistFile,
&ppf);
if (SUCCEEDED(hres))
{
WORD wsz[MAX_PATH];
// Ensure that the string is ANSI.
MultiByteToWideChar(CP_ACP, 0, lpszPathLink, -1,
wsz, MAX_PATH);
// Save the link by calling IPersistFile::Save.
hres = ppf->lpVtbl->Save(ppf, wsz, TRUE);
ppf->lpVtbl->Release(ppf);
}
psl->lpVtbl->Release(psl);
}
CoUninitialize();
return hres;
}
-
Aug 14th, 2000, 07:40 PM
#2
Code:
Private Declare Function fCreateShellLink Lib "STKIT432.DLL" _
(ByVal lpstrFolderName as String, ByVal lpstrLinkName _
as String, ByVal lpstrLinkPath as String, ByVal _
lpstrLinkArgs as String) As Long
Private Sub Form_Load()
lngResult = fCreateShellLink("....Desktop", _
"Link to my program", "C:\Path\Program.exe","")
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|