Search:
Namespaces
Discussions
.NET v1.1
Feedback
struct layout of SHITEMID
Messages
Related Types
This message was discovered on
microsoft.public.dotnet.framework.interop
.
Post a new message to this list...
style
Hi
I'm trying to define the following C++ shell struct in C# (see shtypes.h or
shtypes.idl):
typedef struct _SHITEMID {
USHORT cb;
BYTE abID[1];
} SHITEMID;
where cb is the size of the whole struct (in bytes) including cb itself and
abID can have a variable length.
here is my definition (I fixed the abID size to 4 bytes - 2 bytes data and 2
bytes for a recommended terminator '\0'):
[StructLayout(
LayoutKind
.Sequential, Size=6)]
public struct SHITEMID
{
public
UInt16
cb; // 2 bytes
public
UInt16
abID; // 2 bytes
// public
UInt16
terminator; // 2 bytes
public SHITEMID(short val)
{
if (val == 0)
cb = 0;
else
cb=6;
abID= val;
// terminator = 0;
}
}
This struct works fine together with the shell. But if I uncomment the two
out commented lines, windows explorer crashes. I have absolutely no idea why
this happens. As you can see, the struct has always a length of 6 bytes -
whether the lines are uncommented or not. And in both cases, the last 2
bytes are zero, right?
Any suggestions? It's driving me crazy. The terminator seems to be the key.
Thanx for your help in advance.
Thomas
PS: Remove !spam. from the mail address to contact me.
Reply to this message...
Mattias Sjögren
Thomas,
[Original message clipped]
How and in which context are you using the struct? Are you providing
PIDLs in for example a namespace extension, or are you just consuming
them?
Explorer doesn't care about the Size attribute you set in managed
code, it only cares about the cb member.
Mattias
--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
|
http://www.dotnetinterop.com
Please reply only to the newsgroup.
Reply to this message...
style
Hello Mattias
Exactly, I'm writing a namespace extension with C# and I'm desperately
trying to send my own pidls to Windows Explorer.
Of course I know, Windows Explorer only cares about the cb member. But if I
set cb to 6 bytes, I have to ensure nevertheless that the struct really has
a length of 6 bytes in unmanaged code - which you can control with the Size
parameter in [StructLayout(
LayoutKind
.Sequential, Size=6)]. Otherwise my
struct delivers wrong data. If my struct is marshalled, the data alignment
of my struct has to be correct, right?
For any reason there still seems to be something wrong with that. Any
further suggestions? I'd appreciate any help.
Best regards from Switzerland
Thomas
PS: Remove !spam. from the mail address to contact me.
..
Reply to this message...
System.Runtime.InteropServices.LayoutKind
System.UInt16
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com