By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,124 Members | 1,566 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,124 IT Pros & Developers. It's quick & easy.

FXCop warning with explicit struct layout

P: n/a
I got a warning from fxcop from the declararation of a struct.

the warning:

"Structures with explicit layout containing misaligned
fields cause crashes on 64 bit platforms"

the struct:

[StructLayout(LayoutKind.Explicit)]
public struct STRRET
{
[FieldOffset(0)]
public UInt32 uType; // One of the STRRET_* values
[FieldOffset(4)]
public IntPtr pOleStr; // must be freed by caller of GetDisplayNameOf
[FieldOffset(4)]
public IntPtr pStr; // NOT USED
[FieldOffset(4)]
public UInt32 uOffset; // Offset into SHITEMID
[FieldOffset(4)]
public IntPtr cStr; // Buffer to fill in (ANSI)
}

Iam now wondering how to fix this potential problem without loosing union
semantics of the struct.

anyone some ideas?

Nov 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Do you intend to distribute on a 64 bit platform?

AFAIK that's the only way to create a union in a struct...

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"cody" <de********@gmx.de> wrote in message
news:Om**************@TK2MSFTNGP12.phx.gbl...
I got a warning from fxcop from the declararation of a struct.

the warning:

"Structures with explicit layout containing misaligned
fields cause crashes on 64 bit platforms"

the struct:

[StructLayout(LayoutKind.Explicit)]
public struct STRRET
{
[FieldOffset(0)]
public UInt32 uType; // One of the STRRET_* values
[FieldOffset(4)]
public IntPtr pOleStr; // must be freed by caller of GetDisplayNameOf
[FieldOffset(4)]
public IntPtr pStr; // NOT USED
[FieldOffset(4)]
public UInt32 uOffset; // Offset into SHITEMID
[FieldOffset(4)]
public IntPtr cStr; // Buffer to fill in (ANSI)
}

Iam now wondering how to fix this potential problem without loosing union
semantics of the struct.

anyone some ideas?

Nov 17 '05 #2

P: n/a
> Do you intend to distribute on a 64 bit platform?

No that is not planned yet but you never know.
AFAIK that's the only way to create a union in a struct...
So there is no portable way to do it. I hoped there is a good solution.

"cody" <de********@gmx.de> wrote in message
news:Om**************@TK2MSFTNGP12.phx.gbl...
I got a warning from fxcop from the declararation of a struct.

the warning:

"Structures with explicit layout containing misaligned
fields cause crashes on 64 bit platforms"

the struct:

[StructLayout(LayoutKind.Explicit)]
public struct STRRET
{
[FieldOffset(0)]
public UInt32 uType; // One of the STRRET_* values
[FieldOffset(4)]
public IntPtr pOleStr; // must be freed by caller of GetDisplayNameOf
[FieldOffset(4)]
public IntPtr pStr; // NOT USED
[FieldOffset(4)]
public UInt32 uOffset; // Offset into SHITEMID
[FieldOffset(4)]
public IntPtr cStr; // Buffer to fill in (ANSI)
}

Iam now wondering how to fix this potential problem without loosing union
semantics of the struct.

anyone some ideas?

Nov 17 '05 #3

P: n/a
The problem seemse to be the IntPtr.
While it's 32-bit on 32-bit plattforms it is 64-bit on 64-bit platforms.
I don't know of thiswould be a problem for your code; it doesn't seeme so,
but you've got to decide yourself.

Christof

"cody" <de********@gmx.de> schrieb im Newsbeitrag
news:Om**************@TK2MSFTNGP12.phx.gbl...
I got a warning from fxcop from the declararation of a struct.

the warning:

"Structures with explicit layout containing misaligned
fields cause crashes on 64 bit platforms"

the struct:

[StructLayout(LayoutKind.Explicit)]
public struct STRRET
{
[FieldOffset(0)]
public UInt32 uType; // One of the STRRET_* values
[FieldOffset(4)]
public IntPtr pOleStr; // must be freed by caller of GetDisplayNameOf
[FieldOffset(4)]
public IntPtr pStr; // NOT USED
[FieldOffset(4)]
public UInt32 uOffset; // Offset into SHITEMID
[FieldOffset(4)]
public IntPtr cStr; // Buffer to fill in (ANSI)
}

Iam now wondering how to fix this potential problem without loosing union
semantics of the struct.

anyone some ideas?

Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.