Microsoft KB Archive/263909

{|
 * width="100%"|

PRB: ShellExecuteEx Limits URL to MAX_PATH

 * }

Q263909

-

The information in this article applies to:


 * Microsoft Win32 Software Development Kit (SDK), on platform(s):
 * Microsoft Windows 95
 * Microsoft Windows NT Server version 4.0
 * Microsoft Windows NT Workstation version 4.0

-

SYMPTOMS
When you use the ShellExecute or ShellExecuteEx function on version 4.0 of the Shell32.dll file to open a URL, the URL is limited to (MAX_PATH - 1) characters. A URL should be able to be as long as (INTERNET_MAX_URL_LENGTH - 1) (defined in Wininet.h) characters.

CAUSE
ShellExecute and ShellExecuteEx copy the file string into an internal buffer. In the original version of Shell32.dll, the buffer's maximum size is MAX_PATH characters. Starting with Shell32.dll version 4.71, this internal buffer is expanded to INTERNET_MAX_URL_LENGTH characters.

RESOLUTION
This problem can be overcome by creating a temporary Internet shortcut file that contains the long URL and passing the Internet shortcut file to ShellExecute or ShellExecuteEx. After calling ShellExecute or ShellExecuteEx, this file can safely be deleted.

Code such as the following can be used to create an Internet shortcut file:

#include 
 * 1) include 
 * 2) include 

/**************************************************************************

CreateInternetShortcut

pszShortcut - Path and file name of the Internet shortcut file. This must have the URL extension for the shortcut to be used correctly.

pszURL - URL to be stored in the Internet shortcut file.

HRESULT CreateInternetShortcut(LPTSTR pszShortcut, LPTSTR pszURL) { IUniformResourceLocator *purl; HRESULT                hr;

hr = CoInitialize(NULL);

if(SUCCEEDED(hr)) {   //Get a pointer to the IShellLink interface. hr = CoCreateInstance( CLSID_InternetShortcut,                            NULL,                            CLSCTX_INPROC_SERVER,                            IID_IUniformResourceLocator,                            (LPVOID*)&purl); if(SUCCEEDED(hr)) {      IPersistFile* ppf;

hr = purl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf);

if(SUCCEEDED(hr)) {        hr = purl->SetURL(pszURL, 0);

if(SUCCEEDED(hr)) {           WCHAR wszShortcut[MAX_PATH];

lstrcpyn(wszShortcut, pszShortcut, MAX_PATH); MultiByteToWideChar( CP_ACP,                                 0,                                  pszShortcut,                                  -1,                                  wszShortcut,                                  MAX_PATH);
 * 1) ifdef UNICODE
 * 1) else
 * 1) endif

hr = ppf->Save(wszShortcut, FALSE); }        ppf->Release; }      purl->Release; }

CoUninitialize; }

return hr; }

STATUS
This behavior has been corrected in version 4.71 and later of Shell32.dll.

Additional query words:

Keywords : kbLib kbOSWinNT400 kbSDKPlatform kbSDKWin32 kbShellGrp kbOSWin95 kbDSupport

Issue type : kbprb

Technology : kbWin32SDKSearch kbAudDeveloper kbSDKSearch kbWin32sSearch