Click here to Skip to main content
15,886,873 members
Home / Discussions / C#
   

C#

 
GeneralRe: Lets start with serious things... Pin
Michael P Butler1-Feb-04 23:46
Michael P Butler1-Feb-04 23:46 
GeneralAdd files to media player Pin
Fleischen1-Feb-04 23:21
Fleischen1-Feb-04 23:21 
GeneralRe: Add files to media player Pin
Fleischen2-Feb-04 3:29
Fleischen2-Feb-04 3:29 
GeneralOpengl & C# Pin
islheg1-Feb-04 22:29
islheg1-Feb-04 22:29 
GeneralRe: Opengl & C# Pin
Mazdak1-Feb-04 22:55
Mazdak1-Feb-04 22:55 
GeneralRead outlook express dbx files Pin
Gambit0071-Feb-04 21:34
Gambit0071-Feb-04 21:34 
GeneralRe: Read outlook express dbx files Pin
Mazdak1-Feb-04 22:51
Mazdak1-Feb-04 22:51 
GeneralUse of Structures in Unmanaged Code Pin
zelbezach1-Feb-04 20:00
zelbezach1-Feb-04 20:00 
I am trying to use the method SizeOf to determine the size of a structure containing arrays, among other elements. I succeeded in doing this by using MarshalAs with UnmanagedType and SizeConst. This works for structures with simple arrays, but for more complicated structures (such as nested ones), it compiles and links, but bombs during execution.

Below is sample code, with comments indicating exactly which line of code makes it bomb, and exactly where it bombs.

Do you have any suggestions? (I am running on .NET)

Thank you very much.


using System ;
using System.IO ;
using System.Runtime.InteropServices;

public class classMain
{
public static void Main ()
{
System.Type type = typeof (CLASS.STRUCT) ;

/* Here it bombs: ===> */ int length = Marshal.SizeOf (type) ;
return ;
}
}

public class CLASS
{
[StructLayout(LayoutKind.Sequential, Pack=1, CharSet=CharSet.Ansi)]
public struct float_3
{
[MarshalAs( UnmanagedType.ByValArray, SizeConst= 3 )]
public float [] FLOAT ;
}

[StructLayout(LayoutKind.Sequential, Pack=1, CharSet=CharSet.Ansi)]
public struct float_3_3
{
[MarshalAs( UnmanagedType.ByValArray, SizeConst= 3 )]
public float_3 [] FLOAT_3 ;
}

[StructLayout(LayoutKind.Sequential, Pack=1, CharSet=CharSet.Ansi)]
public struct STRUCT
{
[MarshalAs( UnmanagedType.ByValArray, SizeConst= 10 )]
ushort [] USHORT ;

[MarshalAs( UnmanagedType.ByValArray, SizeConst= 2 )]
/* This makes it bomb: ===> */ public float_3_3 [] FLOAT_3_3 ;
}
}


zelbezach
GeneralC# Pin
BP1281-Feb-04 15:55
BP1281-Feb-04 15:55 
GeneralRe: C# Pin
Jonathan Slenders_2-Feb-04 0:47
sussJonathan Slenders_2-Feb-04 0:47 
GeneralRe: C# Pin
Heath Stewart2-Feb-04 3:47
protectorHeath Stewart2-Feb-04 3:47 
GeneralInclude .NET Pin
adyrds1-Feb-04 11:48
adyrds1-Feb-04 11:48 
GeneralRe: Include .NET Pin
Bo Hunter1-Feb-04 12:12
Bo Hunter1-Feb-04 12:12 
GeneralRe: Include .NET Pin
jkerns2-Feb-04 2:41
jkerns2-Feb-04 2:41 
GeneralRe: Include .NET Pin
Heath Stewart2-Feb-04 4:01
protectorHeath Stewart2-Feb-04 4:01 
GeneralRe: Include .NET Pin
Anonymous2-Feb-04 10:28
Anonymous2-Feb-04 10:28 
GeneralPopup menus (please help me) Pin
Jonathan S1-Feb-04 9:26
Jonathan S1-Feb-04 9:26 
GeneralRe: Popup menus (please help me) Pin
Nick Parker1-Feb-04 9:32
protectorNick Parker1-Feb-04 9:32 
GeneralWin32 API functions Pin
zlaty1-Feb-04 9:11
zlaty1-Feb-04 9:11 
GeneralRe: Win32 API functions Pin
Nick Parker1-Feb-04 9:37
protectorNick Parker1-Feb-04 9:37 
GeneralRe: Win32 API functions Pin
zlaty1-Feb-04 9:46
zlaty1-Feb-04 9:46 
GeneralRe: Win32 API functions Pin
Mazdak1-Feb-04 9:37
Mazdak1-Feb-04 9:37 
GeneralRe: Win32 API functions Pin
zlaty1-Feb-04 9:46
zlaty1-Feb-04 9:46 
GeneralRe: Win32 API functions Pin
Nick Parker1-Feb-04 9:53
protectorNick Parker1-Feb-04 9:53 
GeneralRe: Win32 API functions Pin
Mazdak1-Feb-04 9:56
Mazdak1-Feb-04 9:56 

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.