Click here to Skip to main content
11,928,003 members (29,793 online)
Click here to Skip to main content
Articles » Languages » C++ / CLI » COM Interop » Downloads


27 bookmarked

Creating and Resolving shell links

, 10 May 2002
An MC++ class that uses IJW to invoke the IShellLink interface
// ShortCut.h

#pragma once

using namespace System;
using namespace System::Runtime::InteropServices;

namespace ShortCutLib
	public __gc class ShortCut
			String* m_filepath;
			String* m_workdir;
			String* m_lnkdesc;
			String* m_lnkpath;

			HRESULT _CreateLink(LPCWSTR FilePath, LPCWSTR LnkPath, LPCWSTR LnkDesc,LPCWSTR WorkDir);
			HRESULT _ResolveLink(LPCWSTR LnkFile, LPWSTR FilePath,LPWSTR LnkDesc,LPWSTR WorkDir);

			__property String* get_FilePath()
				return m_filepath;
			__property void set_FilePath(String *str)
				m_filepath = str;
			__property String* get_WorkDir()
				return m_workdir;
			__property void set_WorkDir(String *str)
				m_workdir = str;
			__property String* get_LnkDesc()
				return m_lnkdesc;
			__property void set_LnkDesc(String *str)
				m_lnkdesc = str;
			__property String* get_LnkPath()
				return m_lnkpath;
			__property void set_LnkPath(String *str)
				m_lnkpath = str;
			bool CreateLink()
				IntPtr strfilepath = Marshal::StringToCoTaskMemUni(FilePath);
				IntPtr strlnkpath = Marshal::StringToCoTaskMemUni(LnkPath);
				IntPtr strlnkdesc = Marshal::StringToCoTaskMemUni(LnkDesc);
				IntPtr strworkdir = Marshal::StringToCoTaskMemUni(WorkDir);
				HRESULT hres = _CreateLink((LPCWSTR)strfilepath.ToPointer(),(LPCWSTR)strlnkpath.ToPointer(),


				return (hres==S_OK);

			bool ResolveLink()
				wchar_t strfilepath[MAX_PATH];
				wchar_t strworkdir[MAX_PATH];
				wchar_t strlnkdesc[INFOTIPSIZE];

				IntPtr strlnkpath = Marshal::StringToCoTaskMemUni(LnkPath);		 
				HRESULT hres = _ResolveLink((LPCWSTR)strlnkpath.ToPointer(),
					strfilepath, strlnkdesc, strworkdir);

				FilePath = strfilepath;
				LnkDesc = strlnkdesc;
				WorkDir = strworkdir;

				return (hres==S_OK);

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Nish Nishant
United States United States
Nish Nishant is a Software Architect/Consultant based out of Columbus, Ohio. He has over 15 years of software industry experience in various roles including Lead Software Architect, Principal Software Engineer, and Product Manager. Nish is a recipient of the annual Microsoft Visual C++ MVP Award since 2002 (13 consecutive awards as of 2014).

Nish is an industry acknowledged expert in the Microsoft technology stack. He authored
C++/CLI in Action for Manning Publications in 2005, and had previously co-authored
Extending MFC Applications with the .NET Framework for Addison Wesley in 2003. In addition, he has over 140 published technology articles on and another 250+ blog articles on his
WordPress blog. Nish is vastly experienced in team management, mentoring teams, and directing all stages of software development.

Contact Nish : You can reach Nish on his google email id voidnish.

Website and Blog

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.151126.1 | Last Updated 11 May 2002
Article Copyright 2002 by Nish Nishant
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid