Click here to Skip to main content
15,897,113 members
Home / Discussions / C#
   

C#

 
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 
GeneralRe: Help with TypeLoadException (marshaling unmanaged code) Pin
Luc Pattyn1-Jul-07 9:14
sitebuilderLuc Pattyn1-Jul-07 9:14 
Questionvalidating a formula Pin
Bojja Lakshmi30-Jun-07 2:50
Bojja Lakshmi30-Jun-07 2:50 
AnswerRe: validating a formula Pin
User 665830-Jun-07 3:32
User 665830-Jun-07 3:32 
QuestionDataGrid with checkbox Pin
-spy-30-Jun-07 2:40
-spy-30-Jun-07 2:40 
AnswerRe: DataGrid with checkbox Pin
DanB198330-Jun-07 8:24
DanB198330-Jun-07 8:24 
QuestionInvalid Argument exception? Pin
$uresh $hanmugam30-Jun-07 1:58
$uresh $hanmugam30-Jun-07 1:58 
AnswerRe: Invalid Argument exception? [modified] Pin
Luc Pattyn30-Jun-07 3:07
sitebuilderLuc Pattyn30-Jun-07 3:07 
Questionreading file error Pin
tauras8130-Jun-07 1:41
tauras8130-Jun-07 1:41 
AnswerRe: reading file error Pin
Luc Pattyn30-Jun-07 1:58
sitebuilderLuc Pattyn30-Jun-07 1:58 
Questionarray of type label Pin
Glen Harvy29-Jun-07 23:47
Glen Harvy29-Jun-07 23:47 
AnswerRe: array of type label Pin
Sathesh Sakthivel29-Jun-07 23:53
Sathesh Sakthivel29-Jun-07 23:53 
GeneralRe: array of type label Pin
Glen Harvy30-Jun-07 0:09
Glen Harvy30-Jun-07 0:09 
AnswerRe: array of type label Pin
Luc Pattyn29-Jun-07 23:57
sitebuilderLuc Pattyn29-Jun-07 23:57 
GeneralRe: array of type label Pin
Glen Harvy30-Jun-07 0:11
Glen Harvy30-Jun-07 0:11 

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.