Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / September 2004

Tip: Looking for answers? Try searching our database.

struct layout of SHITEMID

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
style - 05 Sep 2004 23:41 GMT
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.
Mattias Sj?gren - 06 Sep 2004 22:44 GMT
Thomas,

>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
[quoted text clipped - 3 lines]
>
>Any suggestions? It's driving me crazy. The terminator seems to be the key.

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

Signature

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

style - 06 Sep 2004 23:57 GMT
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.
.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.