473,473 Members | 2,092 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Type * can not be marshaled as an unmanaged structure

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?
Jul 21 '05 #1
4 19048
> [MarshalAs(UnmanagedType.ByValArray, SizeConst=Kernel.MAX_PATH)]
public string szDisplayName;


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

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jul 21 '05 #2

"the openBack" <th**********@yahoo.com> wrote in message
news:42***********************@news.usenetmonster. com...
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
Jul 21 '05 #3
Scratch that.

David
"David Browne" <davidbaxterbrowne no potted me**@hotmail.com> wrote in
message news:Ob**************@TK2MSFTNGP12.phx.gbl...

"the openBack" <th**********@yahoo.com> wrote in message
news:42***********************@news.usenetmonster. com...
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

Jul 21 '05 #4
Mattias Sjögren wrote:
[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!
Jul 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: JC | last post by:
How does garbage collection work in C# and VB.NET for data returned from COM object? For example, a COM object written in C++ returns a SAFEARRAY to C# or VB.NET, will this SAFEARRAY (mapped to...
1
by: vijaya | last post by:
I've to invoke a unmanaged dll fucntion in C# which uses a callback fucntion.The unmanaged dll fucntion returns a pointer to a structure to its callback fucntion.The user should collect those...
7
by: Lei Jiang | last post by:
I'd like to calculate the memory size that my data structure cost, but I could not find any API that I could calculate the size of an object. Could anyone give me a work around? Thanks!
1
by: Chakravarthy Bollapalli \(IFIN SCC COM\) | last post by:
Hi, I get the exception ====exception======= An unhandled exception of type 'System.TypeLoadException' occurred in Test.exe Additional information: Can not marshal field si of type...
3
by: zhphust | last post by:
I want to convert a object of a managed class to a unmanaged structure that has the same member with that managed class. Can anybody tell me how i can do it? Thanks in advance. -- zhphust...
4
by: the openBack | last post by:
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 {
4
by: taskswap | last post by:
I'm converting an application that relies heavily on a binary network protocol. Within this protocol are a lot of byte arrays of character data, like: public unsafe struct MsgAddEntry {...
4
by: donald | last post by:
how to get the length of variable for differernt data type, such as data type of structure, integer, date, etc. Thanks in advance.
6
by: Aston Martin | last post by:
Hi All, ********************** My Situation ********************** I am working on project that involves passing a structure to unmanaged code from .Net world (well using C#). Perhaps an example...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.