4 Replies - 5803 Views - Last Post: 23 August 2009 - 07:21 PM Rate Topic: -----

#1 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Unable to find an entry point ... {RESOLVED}

Posted 23 August 2009 - 02:48 PM

Ok this one is really confusing to me. I'm working on something (Got a signed NDA so I cant say what right now) but Im needing to get all the start up items and display them in a ListView. There's going to be quite a bit of code here so I apologize. I have an IconShortcut class that is using the Win32 API ExtractIcon function.

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#

Is This A Good Question/Topic? 0
  • +

Replies To: Unable to find an entry point ... {RESOLVED}

#2 lesPaul456  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 173
  • View blog
  • Posts: 729
  • Joined: 16-April 09

Re: Unable to find an entry point ... {RESOLVED}

Posted 23 August 2009 - 03:15 PM

You just need to change the signatrue to:

[DllImport("shell32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern IntPtr ExtractIcon(IntPtr hInst, string lpszExeFileName, int nIconIndex);



This should work (at least it did for me :) ).

Hope this helps!
Was This Post Helpful? 1
  • +
  • -

#3 Core  Icon User is offline

  • using System.Linq;
  • member icon

Reputation: 774
  • View blog
  • Posts: 5,097
  • Joined: 08-December 08

Re: Unable to find an entry point ... {RESOLVED}

Posted 23 August 2009 - 03:19 PM

For some reason it works on my side without signature modification (running Windows 7 RC). I don't think the problem is in the shell32.dll.
Was This Post Helpful? 0
  • +
  • -

#4 lesPaul456  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 173
  • View blog
  • Posts: 729
  • Joined: 16-April 09

Re: Unable to find an entry point ... {RESOLVED}

Posted 23 August 2009 - 03:45 PM

Shouldn't the ExactSpelling attribute be set to false when CharSet is set to Auto anyway?
Here's why I ask: http://msdn.microsof...ctspelling.aspx (read the remarks).

This post has been edited by lesPaul456: 23 August 2009 - 03:46 PM

Was This Post Helpful? 0
  • +
  • -

#5 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Unable to find an entry point ... {RESOLVED}

Posted 23 August 2009 - 07:21 PM

@lesPaul456: Thanks a lot! I knew it had to be something sinple :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1