Whenever I try to get the shortcut icon for a startup item I get this message
Quote
Unable to find an entry point named 'ExtractIcon' in DLL 'shell32.dll'.
Here is the declaration of ExtractIcon
[DllImport("shell32.dll", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)]
public static extern IntPtr ExtractIcon(IntPtr hInst, string lpszExeFileName, int nIconIndex);
Here's the Icon property that is generating the error
/// <summary>
/// Retrieves the Icon of the shortcut as it will appear in Explorer.
/// Use the IconPath and IconIndex properties to change it.
/// </summary>
public Icon Icon
{
get
{
StringBuilder sb = new StringBuilder(MAX_PATH);
int nIconIdx = 0;
IntPtr hIcon = default(IntPtr);
IntPtr hInst = default(IntPtr);
Icon ico = null;
Icon clone = null;
link.GetIconLocation(sb, sb.Capacity, ref nIconIdx);
hInst = Marshal.GetHINSTANCE(this.GetType().Module);
hIcon = Win32.ExtractIcon(hInst, sb.ToString(), nIconIdx);
if (hIcon.ToInt32() == 0) return null;
// Return a cloned Icon, because we have to free the original ourself.
ico = System.Drawing.Icon.FromHandle(hIcon);
clone = (Icon)ico.Clone();
ico.Dispose();
Win32.DestroyIcon(hIcon);
return clone;
}
}
Here's the declaration of the variable link
private IShellLinkW link;
And the interface IShellLinkW
[ComImport(), InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown), Guid("000214F9-0000-0000-C000-000000000046")]
internal interface IShellLinkW
{
void GetPath([In, Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszFile, int cchMaxPath, [In,Out] ref XPUtilitiesProStructs.WIN32_FIND_DATAW pfd, Enums.SLGP_FLAGS fFlags);
void GetIDList(ref IntPtr ppidl);
void SetIDList(IntPtr pidl);
void GetDescription([Out(), MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszName, int cchMaxName);
void SetDescription([MarshalAs(UnmanagedType.LPWStr)] string pszName);
void GetWorkingDirectory([Out(), MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszDir, int cchMaxPath);
void SetWorkingDirectory([MarshalAs(UnmanagedType.LPWStr)] string pszDir);
void GetArguments([Out(), MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszArgs, int cchMaxPath);
void SetArguments([MarshalAs(UnmanagedType.LPWStr)] string pszArgs);
void GetHotkey(ref short pwHotkey);
void SetHotkey(short wHotkey);
void GetShowCmd(ref int piShowCmd);
void SetShowCmd(int iShowCmd);
void GetIconLocation([Out(), MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszIconPath, int cchIconPath, ref int piIcon);
void SetIconLocation([MarshalAs(UnmanagedType.LPWStr)] string pszIconPath, int iIcon);
void SetRelativePath([MarshalAs(UnmanagedType.LPWStr)] string pszPathRel, int dwReserved);
void Resolve(IntPtr hwnd, Enums.SLR_FLAGS fFlags);
void SetPath([MarshalAs(UnmanagedType.LPWStr)] string pszFile);
}
I can show more code if need be. Here's the weird thing, I can get it to work in VB.NET, but the application needs to be in C#

New Topic/Question
Reply



MultiQuote




|