Skip to content

Explicit structure layout and constructor #7261

Answered by huoyaoyuan
levicki asked this question in Q&A
Discussion options

You must be logged in to vote
  1. Wouldn't that be inefficient (initializing everything to 0/null/IntPtr.Zero or whatever default) only to get overwritten right away?

You can use Unsafe.SkipInit(out this) to skip the check.

  1. If both values are initialized which one will be taken by the marshaler?

FieldOffset is often handled by the runtime. Only one value will be stored.

BTW your P/Invoke code is wrong, because SIGNER_FILE_INFO and SIGNER_BLOB_INFO should be pointers instead of nested structs. I'd suggest using CsWin32 to auto generate P/Invoke code for correctness.

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@FaustVX
Comment options

@333fred
Comment options

@levicki
Comment options

@huoyaoyuan
Comment options

Answer selected by levicki
@levicki
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants