On May 7, 1:02 am, "John Vottero" <JVott...@mvpsi.com> wrote:
> <guy.gorod...@googlemail.com> wrote in message
>
> news:(E-Mail Removed)...
>
>
>
>
>
> > On May 6, 1:03 pm, "Alberto Poblacion" <earthling-
> > quitaestoparacontes...@poblacion.org> wrote:
> >> <guy.gorod...@googlemail.com> wrote in message
>
> >>news:(E-Mail Removed)...
>
> >> > i have a c# interop that pass struct into c dll. for some reason the
> >> > data transfered into the c function is with incorrect order (meaning -
> >> > members of the struct get other struct values and other members get
> >> > zero)
> >> > can someone know how can i fix it?
>
> >> There is probably some difference in the way that C# and C are laying
> >> out
> >> the structure, such as members that are not 32-bits long being aligned on
> >> different boundaries. In C# you can apply to your struct the attributes
> >> [StructLayout(...)] and [FieldOffset(...)] which let you fine-tune the
> >> internal layout of the struct so that you can match the layout of the
> >> struct
> >> in the dll.
>
> > i have used [StructLayout(LayoutKind.Sequential)] and it didn't
> > helped.
> > my struct contains 6 members: first two are enums and the other are
> > UINT32.
> > when i pass them into the c function the enums pass o.k but the other
> > members are shifted - 3rd and 4th get 0, 5th get the value the should
> > have been of the 3rd, and 6th get the value that should have been of
> > the 4th.
>
> > any suggestion?
>
> Your StructLayout Pack isn't set to what you expect. The Framework is
> adding padding between the enums and the UINT32s, that's what the zeros are
> and that's why 3 and 4 seem to be in 5th and 6th position.- Hide quoted text -
>
> - Show quoted text -
i have found my problem, i have defined inside the c file by mistake
one of the members as INT8 instead of INT32
so that what cause me the shifting!
thanks you all,
|