473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

FXCop warning with explicit struct layout

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
3 2023
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
> 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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Chua Wen Ching | last post by:
Hi there, I am super confuse on this recommendation by FxCop. 1) http://www.gotdotnet.com/team/fxcop/docs/rules/UsageRules/OperatorEqualsOverridesRequireEqualsOverridel.html First of all,...
0
by: bns | last post by:
Hi, am integrating quantization technique (OctreeQuantizer.cs, Quantizer.cs) in image processing assembly component which is a C# library application. My requirement is after compiling the...
5
by: Peter Ritchie [C# MVP] | last post by:
I've purposely been ignoring a CA2122 warning in some C++ interop code I've been working on for quite some time. I've just recently had the cycles to investigate the warning. The warning message...
6
by: James H. Newman | last post by:
I am playing with some code that has been automatically generated from ASN.1 data specification found in RFC 3280. One of the structures generated reads as follows: typedef struct TBSCertList {...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.