Click here to Skip to main content
15,906,645 members
Home / Discussions / C#
   

C#

 
QuestionSave data into a .dat file Pin
atlasliu30-Jun-07 14:44
atlasliu30-Jun-07 14:44 
AnswerRe: Save data into a .dat file Pin
Luc Pattyn30-Jun-07 14:59
sitebuilderLuc Pattyn30-Jun-07 14:59 
QuestionImage Processing using C# Pin
marwa wael30-Jun-07 7:04
marwa wael30-Jun-07 7:04 
AnswerRe: Image Processing using C# Pin
zeeShan anSari30-Jun-07 9:01
zeeShan anSari30-Jun-07 9:01 
QuestionImageprocessing:Draw and Save the drawing Pin
zeeShan anSari30-Jun-07 6:34
zeeShan anSari30-Jun-07 6:34 
AnswerRe: Imageprocessing:Draw and Save the drawing Pin
Guffa30-Jun-07 6:49
Guffa30-Jun-07 6:49 
AnswerRe: Imageprocessing:Draw and Save the drawing Pin
zeeShan anSari30-Jun-07 8:54
zeeShan anSari30-Jun-07 8:54 
GeneralRe: Imageprocessing:Draw and Save the drawing Pin
Christian Graus30-Jun-07 10:39
protectorChristian Graus30-Jun-07 10:39 
AnswerRe: Imageprocessing:Draw and Save the drawing Pin
Guffa30-Jun-07 11:34
Guffa30-Jun-07 11:34 
AnswerRe: Imageprocessing:Draw and Save the drawing Pin
Christian Graus30-Jun-07 10:30
protectorChristian Graus30-Jun-07 10:30 
Questionhow to access database Pin
nidesh30-Jun-07 5:07
nidesh30-Jun-07 5:07 
AnswerRe: how to access database Pin
WillemM30-Jun-07 6:58
WillemM30-Jun-07 6:58 
AnswerRe: how to access database Pin
Paul Conrad30-Jun-07 7:10
professionalPaul Conrad30-Jun-07 7:10 
GeneralRe: how to access database Pin
Expert Coming30-Jun-07 11:06
Expert Coming30-Jun-07 11:06 
GeneralRe: how to access database Pin
Paul Conrad30-Jun-07 14:02
professionalPaul Conrad30-Jun-07 14:02 
QuestionHelp with TypeLoadException (marshaling unmanaged code) Pin
TomWolfstein30-Jun-07 4:50
TomWolfstein30-Jun-07 4:50 
AnswerRe: Help with TypeLoadException (marshaling unmanaged code) Pin
Luc Pattyn30-Jun-07 5:10
sitebuilderLuc Pattyn30-Jun-07 5:10 
GeneralRe: Help with TypeLoadException (marshaling unmanaged code) Pin
TomWolfstein30-Jun-07 6:05
TomWolfstein30-Jun-07 6:05 
GeneralRe: Help with TypeLoadException (marshaling unmanaged code) Pin
Luc Pattyn30-Jun-07 6:57
sitebuilderLuc Pattyn30-Jun-07 6:57 
GeneralRe: Help with TypeLoadException (marshaling unmanaged code) Pin
TomWolfstein30-Jun-07 8:51
TomWolfstein30-Jun-07 8:51 
GeneralRe: Help with TypeLoadException (marshaling unmanaged code) Pin
Luc Pattyn30-Jun-07 14:27
sitebuilderLuc Pattyn30-Jun-07 14:27 
GeneralRe: Help with TypeLoadException (marshaling unmanaged code) Pin
TomWolfstein1-Jul-07 7:16
TomWolfstein1-Jul-07 7:16 
Hi.
I tried what you suggested and came up with the conclusion that there is no extra padding for structs.
The 64 bytes I calculated is the same size i got from Marshal.SizeOf and from the C code.

What I also found out is that you cannot use LayoutKind.Explicit and FieldOffset in a struct that has both values and refrences (or with refrences at all).
Check out Mattias Sjögren reply here:
http://www.dotnet247.com/247reference/msgs/5/27796.aspx[^]

So I worked around (I hope) the union problem by creating a struct that contains those two fields, and now it looks like this:

/** Description: Structure defining the state required for a block.*/<br />
        [StructLayout(LayoutKind.Sequential)]<br />
        public unsafe struct vc1_sBlk<br />
            {<br />
               public vc1_eBlkType eBlkType;       /** Block type */<br />
               public byte Coded;          /** Non zero AC coefficients for Intra, non zero AC/DC for Inter */<br />
               public union u; //a workaround<br />
            };<br />
        <br />
/** A workaround for the union defined in the vc1_sBlk structure*/<br />
        [StructLayout(LayoutKind.Sequential)]<br />
        public unsafe struct union<br />
            {<br />
            <br />
                public vc1_sBlkIntra sIntra;         /** Intra block state information */<br />
                public vc1_sBlkIntra sInter;         /** Inter block state information */<br />
            };

So now these structs are completely managed and there is no need for the explicit layout anymore. Hwever, this didn't dolve the problem, which leads me to belive that I have asked the wrong question.

The original problem came up when I tried to do this:
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)] public vc1_sBlk[] sBlk;
And no matter what I tried to marshal 'vc1_sBlk' or 'vc1_sBlkIntra', I kept getting the exception. So i tried removing the structures (which are refrences AFAIK) from 'vc1_sBlk' and it worked. Then I returned the structures, but changed the decleration to
public vc1_sBlk sBlk;
and it also worked. Everything is accessible and works fine.
So the question is can I declare a marshalled array that has refrences in it, and if not (which I assume is the case), how can I work around it?

Tom
(Sorry I am pouring all this data on you. I am just trying to be detailed to help you help me, and anyone else who should encounter this problem).
GeneralRe: Help with TypeLoadException (marshaling unmanaged code) Pin
Luc Pattyn1-Jul-07 8:34
sitebuilderLuc Pattyn1-Jul-07 8:34 
GeneralRe: Help with TypeLoadException (marshaling unmanaged code) Pin
TomWolfstein4-Jul-07 21:57
TomWolfstein4-Jul-07 21:57 
GeneralRe: Help with TypeLoadException (marshaling unmanaged code) Pin
Luc Pattyn5-Jul-07 0:17
sitebuilderLuc Pattyn5-Jul-07 0:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.