Microsoft KB Archive/229092

= How To Create Shortcuts to URLs with IUniformResourceLocator =

Article ID: 229092

Article Last Modified on 2/12/2007

-

APPLIES TO

 Microsoft Windows 98 Standard Edition, when used with:  Microsoft Windows 95

 Microsoft Windows 98 Standard Edition  Microsoft Windows NT Server 4.0 Standard Edition Microsoft Windows NT 4.0 Service Pack 4 Microsoft Windows NT Workstation 4.0 Developer Edition</li> Microsoft Windows NT Workstation 4.0 Developer Edition</li> Microsoft Internet Explorer 4.0 128-Bit Edition</li> Microsoft Internet Explorer 4.01 Service Pack 2</li> Microsoft Internet Explorer 4.01 Service Pack 1</li> Microsoft Internet Explorer 4.01 Service Pack 2</li></ul>

-

<div class="notice_section">

This article was previously published under Q229092

<div class="summary_section">

SUMMARY
IShellLink is used to create shortcuts to files. Similarily IUniformResourceLocator can be used to create shortcuts to URLs.

<div class="moreinformation_section">

MORE INFORMATION
The following sample code shows how to use the interface IUniformResourceLocator to create a shortcut to a URL. It creates a URL shortcut file at "C:\Mssupport.url" that points to the URL "http://support.microsoft.com."
 * 1) include <windows.h>
 * 2) include <intshcut.h>

HRESULT CreateShortcutToURL(LPCSTR pszURL, LPCSTR pszLinkFile);

int main { CoInitialize(NULL); HRESULT hRes = CreateShortcutToURL("http://support.microsoft.com","c:\\mssupport.url"); if (SUCCEEDED(hRes)) {   // do something... } CoUninitialize; return 0; }

HRESULT CreateShortcutToURL(LPCSTR pszURL, LPCSTR pszLinkFile) { HRESULT hRes; IUniformResourceLocator *pURL = NULL;

// Create an IUniformResourceLocator object hRes = CoCreateInstance (CLSID_InternetShortcut, NULL,    CLSCTX_INPROC_SERVER, IID_IUniformResourceLocator, (LPVOID*) &pURL); if (SUCCEEDED(hRes)) {   IPersistFile *pPF = NULL;

hRes = pURL->SetURL(pszURL, 0);

if (SUCCEEDED(hRes)) {     WCHAR wsz [MAX_PATH];   // buffer for Unicode string

// Ensure that the string consists of ANSI characters. MultiByteToWideChar (CP_ACP, 0, pszLinkFile, -1, wsz, MAX_PATH);

hRes = pURL->QueryInterface (IID_IPersistFile, (void **)&pPF); if (SUCCEEDED(hRes)) {          // Save the shortcut via the IPersistFile::Save member function. hRes = pPF->Save (wsz, TRUE);

// Release the pointer to IPersistFile. pPF->Release ; }   }    // Release the pointer to IUniformResourceLocator pURL->Release ; } return hRes; }

Keywords: kbhowto KB229092

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.