Type * can not be marshaled as an unmanaged structure

  • Thread starter Thread starter the openBack
  • Start date Start date
T

the openBack

I'm having a problem that I don't quite understand. I'm using someone
else's class:


using HANDLE = System.IntPtr;

namespace Win32 {
// other stuff here

public struct SHFILEINFO {
public HANDLE hIcon;
public int iIcon;
public int dwAttributes;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=Kernel.MAX_PATH)]
public string szDisplayName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=80)]
public string szTypeName;
}

// other stuff here

}

but when I try to use it in a shell function I get an exception:
"Type Win32.SHFILEINFO can not be marshaled as an unmanaged structure;
no meaningful size or offset can be computed." when I attempt to use

System.Marshal.SizeOf(shinfo)

in a function call (as a parameter to SHGetFileInfo) where shinfo is an
SHFILEINFO object. I don't understand the marshalling very well, so this
is kind of stumping me. Can anyone help?
 
[MarshalAs(UnmanagedType.ByValArray, SizeConst=Kernel.MAX_PATH)]
public string szDisplayName;

Change ByValArray to ByValTStr. ByValArray can only be used with
arrays.



Mattias
 
the openBack said:
I'm having a problem that I don't quite understand. I'm using someone
else's class:


using HANDLE = System.IntPtr;

namespace Win32 {
// other stuff here

public struct SHFILEINFO {
public HANDLE hIcon;
public int iIcon;
public int dwAttributes;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=Kernel.MAX_PATH)] public
string szDisplayName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=80)]
public string szTypeName;
}

// other stuff here

}

but when I try to use it in a shell function I get an exception:
"Type Win32.SHFILEINFO can not be marshaled as an unmanaged structure; no
meaningful size or offset can be computed." when I attempt to use

System.Marshal.SizeOf(shinfo)

Marshal.SizeOf() is not the same thing as C's sizeof operator. You need to
determine the size of the marshalled structure youself and pass it to the
function. Also you can always marshal it as a big byte array and sort it
out after the fact.

David
 
Scratch that.

David
David Browne said:
the openBack said:
I'm having a problem that I don't quite understand. I'm using someone
else's class:


using HANDLE = System.IntPtr;

namespace Win32 {
// other stuff here

public struct SHFILEINFO {
public HANDLE hIcon;
public int iIcon;
public int dwAttributes;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=Kernel.MAX_PATH)] public
string szDisplayName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=80)]
public string szTypeName;
}

// other stuff here

}

but when I try to use it in a shell function I get an exception:
"Type Win32.SHFILEINFO can not be marshaled as an unmanaged structure; no
meaningful size or offset can be computed." when I attempt to use

System.Marshal.SizeOf(shinfo)

Marshal.SizeOf() is not the same thing as C's sizeof operator. You need
to determine the size of the marshalled structure youself and pass it to
the function. Also you can always marshal it as a big byte array and sort
it out after the fact.

David
 
Mattias said:
[MarshalAs(UnmanagedType.ByValArray, SizeConst=Kernel.MAX_PATH)]
public string szDisplayName;


Change ByValArray to ByValTStr. ByValArray can only be used with
arrays.



Mattias

That was it, thank you! I should've seen something like that, but "Marshal" is very vague to me.
THANKS!
 
Back
Top