PC Review


Reply
Thread Tools Rate Thread

how to dereference link (.lnk)

 
 
Franz
Guest
Posts: n/a
 
      18th Aug 2003
I want to get the path of the file which the lnk file points to.
I know I can use the IShellLink
But I don't know anything about COM. I get COMException when I create an instane of ShellLinkObjectClass.

using System.Management;
using System.Runtime.InteropServices;
[
ComImport(),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
Guid("0000010B-0000-0000-C000-000000000046")
]
public interface IPersistFile
{
void GetClassID(out Guid pClassID);
[PreserveSig()]
int IsDirty();
void Load([MarshalAs(UnmanagedType.LPWStr)] string pszFileName, int dwMode);

void Save([MarshalAs(UnmanagedType.LPWStr)] string pszFileName,
[MarshalAs(UnmanagedType.Bool)] bool fRemember);

void SaveCompleted([MarshalAs(UnmanagedType.LPWStr)] string pszFileName);

void GetCurFile(out IntPtr ppszFileName);
}

public class GetLnkFileMan
{
private const int STGM_READ = 0;
private string _strPath, _strDescription, _strErrorMessage;
public string Path
{
get { return _strPath; }
}
public string Description
{
get { return _strDescription; }
}
public string ErrorMessage
{
get { return _strErrorMessage; }
}
public GetLnkFileMan()
{
}
public bool GetLinkInfo(string strLnkFilePath)
{
try
{
_strErrorMessage = String.Empty;
Interop.Shell32.ShellLinkObjectClass aShellLink = new Interop.Shell32.ShellLinkObjectClass();
IPersistFile aPersistFile = (IPersistFile)aShellLink;
aPersistFile.Load(strLnkFilePath, STGM_READ);
aShellLink.Resolve(0);
_strPath = aShellLink.Path;
_strDescription = aShellLink.Description;
return true;
}
catch (COMException comex)
{
_strErrorMessage = comex.Message;
return false;
}
}
}


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dereference pointer in inline assembly =?Utf-8?B?RXVwaGlsb3M=?= Microsoft VC .NET 3 11th Oct 2006 08:26 AM
link problem. paste into browser works Front Page link doesn't? =?Utf-8?B?bW9kZmVhcg==?= Microsoft Frontpage 3 9th Dec 2005 02:35 PM
Re: Link Link Link DANGER WILL ROBINSON!!! Kevin Spencer Microsoft ASP .NET 0 17th May 2005 11:41 AM
Can't dereference a missing DLL Todd Prickett Microsoft Excel Programming 1 6th Apr 2004 09:06 PM
Re: dereference pointer to object Fergus Cooney Microsoft VB .NET 0 8th Nov 2003 01:13 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:36 AM.