Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

And an example of using a c++ api in c#

 

[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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...