472,378 Members | 1,443 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,378 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 18008
> [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: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...
0
by: F22F35 | last post by:
I am a newbie to Access (most programming for that matter). I need help in creating an Access database that keeps the history of each user in a database. For example, a user might have lesson 1 sent...

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.