Hello,
if I try to call my function:
public static string GetDisplayNameFromPidl(IntPtr Pidl)
{
SHFILEINFOBYTE fileinfobyte = new SHFILEINFOBYTE(true);
try
{
SHGetFileInfoPidl(
(uint) Pidl,
0,
out fileinfobyte,
(uint) Marshal.SizeOf(fileinfobyte),
SHGFI.SHGFI_PIDL | SHGFI.SHGFI_DISPLAYNAME);
}
// ExecutionEngineException
catch(ExecutionEngineException ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
catch(Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
return(fileinfobyte.szDisplayName);
}
/////////////
dll import:
////////////
[DllImport("shell32.dll",EntryPoint="SHGetFileInfoA ", CharSet=CharSet.Auto)]
private static extern int SHGetFileInfoPidl(
uint Pidl,
uint FileAttributes,
out SHFILEINFOBYTE fib,
uint FileInfo,
SHGFI Flags);
//////////////////////
Struct SHFILEINFOBYTE
//////////////////////
[StructLayout(LayoutKind.Sequential)]
private struct SHFILEINFOBYTE
{
public SHFILEINFOBYTE(bool b)
{
hIcon=IntPtr.Zero;iIcon=0;dwAttributes=0;szDisplay Name="";szTypeName="";
}
public IntPtr hIcon;
public int iIcon;
public uint dwAttributes;
[MarshalAs(UnmanagedType.LPStr, SizeConst=260)]
public string szDisplayName;
[MarshalAs(UnmanagedType.LPStr,SizeConst=80)]
public string szTypeName;
}
I get an uncatchable ExecutionEngineException and my program crashs.
It there any way to bring that to work?
Does anyone know any solutions?
The whole project can be found here:
http://tinyurl.com/62a3y
Thanks,
Benjamin