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

C#

 
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 
Hi.
I am trying to write a wrapper for the standard VC1 decoder, and I need to resolve a "TypeLoadException"
The decoder comes an an executable which I've turned into a .dll. This decoder has about a ton of structures, most of the containing other structures, arrays of structures, and unions of structures.

I need help converting the following to managed code:
The unmanaged structure is this:

typedef struct<br />
{<br />
    vc1_eBlkType        eBlkType;       /** Block type */<br />
    FLAG                Coded;          /** Non zero AC coefficients for Intra,<br />
                                            non zero AC/DC for Inter */<br />
    union<br />
    {<br />
        vc1_sBlkIntra   sIntra;         /** Intra block state information */<br />
        vc1_sBlkInter   sInter;         /** Inter block state information */<br />
    }                   u;              /** Intra/Inter union */<br />
} vc1_sBlk;


As you can see it contains an enumerator and a union of another type of struct.
I've taken the unmanaged vc1_sBlkInter structure
typedef struct<br />
{<br />
    vc1_NumZeroCoef     NZC;            /** NUMZERO and NUMCOEF (excludes DC) */<br />
    HWD16               DC;             /** Quantized DC for prediction */<br />
    HWD16               ACTop[7];       /** Quantized AC top row for prediction */<br />
    HWD16               ACLeft[7];      /** Quantized AC left column for prediction */<br />
    HWD16               SmoothRows[16]; /** Bottom two rows kept for overlap smoothing */<br />
} vc1_sBlkIntra;


And turned it into a managed structure :
[StructLayout(LayoutKind.Sequential)]<br />
        public unsafe struct vc1_sBlkIntra<br />
            {<br />
                ushort NZC;            /** NUMZERO and NUMCOEF (excludes DC) */<br />
                short DC;             /** Quantized DC for prediction */<br />
<br />
                [MarshalAs(UnmanagedType.ByValArray, SizeConst = 7)] public short[] ACTop; /** Quantized AC top row for prediction */<br />
                <br />
                [MarshalAs(UnmanagedType.ByValArray, SizeConst = 7)] public short[] ACLeft; /** Quantized AC left column for prediction */<br />
                [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public short[] moothRows; /** Bottom two rows kept for overlap smoothing */<br />
            };


Now, I am trying to turn vc1_sBlk into a managed structure as well.
The last attempt is this
[StructLayout(LayoutKind.Explicit, CharSet = CharSet.Ansi)]<br />
public unsafe struct vc1_sBlk<br />
{<br />
    [FieldOffset(0), MarshalAs(UnmanagedType.I4)]<br />
    public vc1_eBlkType eBlkType;       /** Block type */<br />
    [FieldOffset(4), MarshalAs(UnmanagedType.AsAny)]<br />
    public byte Coded;          /** Non zero AC coefficients for Intra, non zero AC/DC for Inter */<br />
    [FieldOffset(5), MarshalAs(UnmanagedType.Struct, SizeConst = 64)] public vc1_sBlkIntra sIntra;         /** Intra block state information */<br />
    [FieldOffset(5), MarshalAs(UnmanagedType.Struct, SizeConst = 64)] public vc1_sBlkIntra sInter;         /** Inter block state information */<br />
} ;

But I have pretty much tried every kind of marshalling mentioned online, but I keep getting this error:
"Could not load type 'vc1_sBlk'...because it contains an object field at offset 5 that is incorrectly aligned or overlapped by a non-object field."
I am really stuck here and I can't find an answer to this anywhere.
ANY help would be greatly appreciated.

Tom
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 
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 

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.