How to Get Special Folder Location?

joe_pool_is

Well-known member
Joined
Jan 18, 2004
Messages
451
Location
Texas
There is a C++ function that I have used in Borland called SHGetSpecialFolderLocation that is actually a Microsoft API call.

Im looking for something similar to this in C#. Does it exist? Can I still use C++ APIs in C#?
 
And an example of using a c++ api in c#

Code:
[DllImport("shell32.dll", SetLastError=true)]
private static extern uint SHGetSpecialFolderLocation(IntPtr hwndOwner, int nFolder, out IntPtr ppidl);

/// <summary>
/// Retrieves a pointer to the <b>ITEMIDLIST</b> structure of a special folder.
/// </summary>
/// <param name="hwndOwner">Handle to the owner window the client should
/// specify if it displays a dialog box or message box.</param>
/// <param name="folder">The folder of interest.</param>
/// <returns>A pointer to the <b>ITEMIDLIST</b> structure of a special folder.</returns>
/// <exception cref="Win32Exception">When the the unmanaged function returns a failure error code.</exception>
public static IntPtr GetSpecialFolderLocation(IntPtr hwndOwner, Environment.SpecialFolder folder)
{
	IntPtr ppidl;
	uint result = SHGetSpecialFolderLocation(hwndOwner, (int) folder, out ppidl);
	if(result != 0)
		throw new Win32Exception();
	return ppidl;
}

Using P/Invoke to Access Win32 APIs
 
Fabulous! Thanks. I was just looking into the thread "Implementing the IActiveDesktop in VB.NET" in the tutorial section, and it is very long! Ill look into your version first.
 
Back
Top