Article View: free.it.visual-basic
Article #68Re: System.Runtime.InteropServices.Marshal.SizeOf(MiaStruttura)
From: Rafunk
Date: Wed, 17 Jan 2007 08:54
Date: Wed, 17 Jan 2007 08:54
57 lines
3015 bytes
3015 bytes
F. wrote:
> Ecco qua:
>
> Private Structure Lettu
> Public IntPiePri As Int32
> Public IntGiaPri As Int32
> Public IntFedPri As Int32
> Public IntRenPri As Int32
> Public IntLinPri As Int32
> Public IntPieNow As Int32
> Public IntGiaNow As Int32
> Public IntFedNow As Int32
> Public IntRenNow As Int32
> Public IntLinNow As Int32
> Public IntImpoPie As Double
> Public IntImpoGia As Double
> Public IntImpoFed As Double
> Public IntImpoRen As Double
> Public IntImpoLin As Double
> Public IntTot As Int32
> Public DatScad As Long
> End Structure
>
> Private MiaStruttura As New Lettu
>
> ' questa espressione mi ritorna 96 byte ->
> System.Runtime.InteropServices.Marshal.SizeOf(MiaStruttura)
>
> Grazie per l'eventuale risposta
� come pensavo io: per allineare correttamente DatScad (che � Long, quindi 8
bytes), quando la struttura passa dal Marshaler, esso viene spostato alla
successiva posizione multipla di 8.
Se il tuo problema � passarla esattamente cos� com'� (senza padding) a codice
unmanaged, devi utilizzare l'attributo StructLayout esplicitando sia la
dimensione totale della struttura, che le posizioni dei campi con l'attributo
FieldOffset:
<StructLayout(LayoutKind.Explicit, Size:=92)> _
Private Structure Lettu
<FieldOffset(0)> _
Public IntPiePri As Int32
<FieldOffset(4)> _
Public IntGiaPri As Int32
...
<FieldOffset(80)> _
Public IntTot As Int32
<FieldOffset(84)> _
Public DatScad As Long
End Structure
A questo punto SizeOf ritorna 92.
Bye
Raf
Technical Details
Message-ID:
<eoko7p$p27$1@alix.livenet.it>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news2.volia.net!newspeer2.de.telia.net!newspeer3.de.telia.net!de.telia.net!aioe.org!news.panservice.it!alix.livenet.it!not-for-mailReferences:
<45ac1594$0$8385$4fafbaef@reader5.news.tin.it> <45ac97fe$0$13253$4fafbaef@reader5.news.tin.it> <45acd996$0$4252$4fafbaef@reader1.news.tin.it>Show Full Headers
Complete Article Headers
X-Google-Thread: f94ee,bc28f55628632a1f X-Google-Attributes: gidf94ee,public X-Google-Language: ITALIAN,CP1252 Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news2.volia.net!newspeer2.de.telia.net!newspeer3.de.telia.net!de.telia.net!aioe.org!news.panservice.it!alix.livenet.it!not-for-mail From: "Rafunk" <rafunkSPAM@NOTHANKSlibero.it> Newsgroups: free.it.visual-basic Subject: Re: System.Runtime.InteropServices.Marshal.SizeOf(MiaStruttura) Date: Wed, 17 Jan 2007 09:54:18 +0100 Organization: MusicOff S.r.l. Lines: 58 Sender: rafunk@musicoff.com Message-ID: <eoko7p$p27$1@alix.livenet.it> References: <45ac1594$0$8385$4fafbaef@reader5.news.tin.it> <45ac97fe$0$13253$4fafbaef@reader5.news.tin.it> <45acd996$0$4252$4fafbaef@reader1.news.tin.it> NNTP-Posting-Host: host150-196.pool8250.interbusiness.it Mime-Version: 1.0 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: 8bit X-Trace: alix.livenet.it 1169024058 25671 82.50.196.150 (17 Jan 2007 08:54:18 GMT) X-Complaints-To: abuse@musicoff.com NNTP-Posting-Date: Wed, 17 Jan 2007 08:54:18 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441