What's the best way to specify structure layout difference on architectures? #55534
-
When trying to modernize P/Invoke in System.Drawing.Common, I saw this: Win32 and Win64 uses different packing size for the struct (confirmed in commdlg.h). This is not easy to define in managed code. Defining two types like this looks very error-prone. Does it worth compiling separately for different archs? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
You can define two types, but hide the difference behind interface. #33899 has real world example of this technique. |
Beta Was this translation helpful? Give feedback.
-
When targeting different architectures like x86 and x64 in P/Invoke scenarios, struct layout can indeed diverge due to alignment and pointer size differences. While defining two separate types and abstracting via interface (as mentioned in #33899) is a practical approach, here are deeper alternatives and considerations: 🧩 1. Use
|
Beta Was this translation helpful? Give feedback.
You can define two types, but hide the difference behind interface. #33899 has real world example of this technique.