473,473 Members | 1,833 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help with TypeLoadException (marshaling unmanaged code)

1 New Member
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:

Expand|Select|Wrap|Line Numbers
  1. typedef struct
  2. {
  3. vc1_eBlkType eBlkType; /** Block type */
  4. FLAG Coded; /** Non zero AC coefficients for Intra,
  5. non zero AC/DC for Inter */
  6. union
  7. {
  8. vc1_sBlkIntra sIntra; /** Intra block state information */
  9. vc1_sBlkInter sInter; /** Inter block state information */
  10. } u; /** Intra/Inter union */
  11. } 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
Expand|Select|Wrap|Line Numbers
  1. typedef struct
  2. {
  3. vc1_NumZeroCoef NZC; /** NUMZERO and NUMCOEF (excludes DC) */
  4. HWD16 DC; /** Quantized DC for prediction */
  5. HWD16 ACTop[7]; /** Quantized AC top row for prediction */
  6. HWD16 ACLeft[7]; /** Quantized AC left column for prediction */
  7. HWD16 SmoothRows[16]; /** Bottom two rows kept for overlap smoothing */
  8. } vc1_sBlkIntra;
And turned it into a managed structure :
Expand|Select|Wrap|Line Numbers
  1. [StructLayout(LayoutKind.Sequential)]
  2. public unsafe struct vc1_sBlkIntra
  3. {
  4. ushort NZC; /** NUMZERO and NUMCOEF (excludes DC) */
  5. short DC; /** Quantized DC for prediction */
  6.  
  7. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 7)] public short[] ACTop; /** Quantized AC top row for prediction */
  8.  
  9. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 7)] public short[] ACLeft; /** Quantized AC left column for prediction */
  10. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public short[] moothRows; /** Bottom two rows kept for overlap smoothing */
  11. };
Now, I am trying to turn vc1_sBlk into a managed structure as well.
The last attempt is this
Expand|Select|Wrap|Line Numbers
  1. [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Ansi)]
  2. public unsafe struct vc1_sBlk
  3. {
  4. [FieldOffset(0), MarshalAs(UnmanagedType.I4)]
  5. public vc1_eBlkType eBlkType; /** Block type */
  6. [FieldOffset(4), MarshalAs(UnmanagedType.AsAny)]
  7. public byte Coded; /** Non zero AC coefficients for Intra, non zero AC/DC for Inter */
  8. [FieldOffset(5), MarshalAs(UnmanagedType.Struct, SizeConst = 64)] public vc1_sBlkIntra sIntra; /** Intra block state information */
  9. [FieldOffset(5), MarshalAs(UnmanagedType.Struct, SizeConst = 64)] public vc1_sBlkIntra sInter; /** Inter block state information */
  10. } ;
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
Jun 30 '07 #1
0 1405

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Scott Dowd | last post by:
I need explicit example of how to use SetupDi* functions in both C# .NET and VB .NET to determine device interface detail for a given device class with interface information detail. All examples...
4
by: Vadym Stetsyak | last post by:
Hi there!!! I'm looking for any resources on the subject. Any help will be appreciated! -- Vadym Stetsyak ICQ 161730125 He, who commands the past - commands the future
1
by: Nadav | last post by:
Hi I am about to write a performance crutial system, I am considering writing this system based on native COM or unmanaged C++ exposed as CLI, Now, I Wonder... does exposing a native code through...
3
by: Salvador | last post by:
Hi, I am using an old Win32 DLL that expects a LPBYTE as a parameter. The Stringbuilder appears to be working, the problem is that the component is sending me a string with NULL characters in the...
3
by: Isaac Lascasas | last post by:
An unhandled exception of type 'System.TypeLoadException' occurred in TDB_CPPInterface.exe Additional information: Could not load type TDS2.IEffect from assembly TDB_CPPInterface,...
2
by: mats | last post by:
Hi! This is a quite involved question concerning two dll's that are consumed from a console application. The first dll is called base.dll and is compiled in mixed mode (managed and unmanaged...
1
by: :\\\\derian | last post by:
Hello All, I'm attempting to add a c# DLL that uses unmanaged code to my VB project. When I add the C# DLL to the project and compile, all goes well but when i hit F5, i get a...
22
by: SQACSharp | last post by:
I'm trying to get the control name of an editbox in another window. The following code set the value "MyPassword" in the password EditBox but it fail to return the control name of the EditBox. ...
3
by: O.B. | last post by:
I recently changed a struct to a class and made its layout Sequential instead of Explicit for Marshalling. And now I'm getting the following error when running my unit tests. I have verified that...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.