I'm trying to P/Invoke a method in shell32.dll. here's the method signature.
LPITEMIDLIST SHBrowseForFolder( LPBROWSEINFO lpbi );
and this is the parameter structure
typedef struct _browseinfo {
HWND hwndOwner;
LPCITEMIDLIST pidlRoot;
LPTSTR pszDisplayName;
LPCTSTR lpszTitle;
UINT ulFlags;
BFFCALLBACK lpfn;
LPARAM lParam;
int iImage;
} BROWSEINFO, *PBROWSEINFO, *LPBROWSEINFO;
and this is how I declared the import and structure in C#
[DllImport( "shell32.dll" )]
private static extern IntPtr SHBrowseForFolder(
[MarshalAs( UnmanagedType.LPStruct ), In, Out] BrowseInfo lpbi );
[StructLayout( LayoutKind.Sequential )]
public class BrowseInfo
{
public IntPtr hwndOwner;
public IntPtr pidlRoot;
[MarshalAs( UnmanagedType.LPStr )]
public string pszDisplayName;
[MarshalAs( UnmanagedType.LPStr )]
public string lpszTitle;
public uint ulFlags;
[MarshalAs( UnmanagedType.FunctionPtr )]
public BrowseCallbackProc lpfn;
public uint lParam;
public int iImage;
}
this works, but my question is, in the original structure pszDisplayName and
lpszTitle are declared as LPTStr (LPCTStr). now when I marshalled them as
LPTStr, and ran on w2k machine, they are marshalled as Unicode strings (which
is correct behavior on the given platform) but the data is in fact
incorrectly marshalled. the method is expected to work with ANSI strings
somehow, when it should really be working with Unicode. anyone know why that
is?