.NETGURU
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...
 
    
Dot Net Guruias 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.

Dot Net Guruias

--
Dot Net Guruias 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 Dot Net Guruias

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




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification