473,396 Members | 1,982 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 19013
> [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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.