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

C#

 
GeneralRe: Buttons in DataGrid Pin
Lyubomir Naydenov2-Feb-04 9:42
Lyubomir Naydenov2-Feb-04 9:42 
QuestionEasy URL Query parsing? Pin
3ddA2-Feb-04 0:08
3ddA2-Feb-04 0:08 
AnswerRe: Easy URL Query parsing? Pin
Heath Stewart2-Feb-04 3:27
protectorHeath Stewart2-Feb-04 3:27 
GeneralRe: Easy URL Query parsing? Pin
3ddA2-Feb-04 6:55
3ddA2-Feb-04 6:55 
GeneralLaunching mail client, open new message and add attachments Pin
jewlin1-Feb-04 23:29
jewlin1-Feb-04 23:29 
GeneralRe: Launching mail client, open new message and add attachments Pin
Heath Stewart2-Feb-04 3:31
protectorHeath Stewart2-Feb-04 3:31 
GeneralRe: Launching mail client, open new message and add attachments Pin
jewlin2-Feb-04 4:48
jewlin2-Feb-04 4:48 
GeneralRe: Launching mail client, open new message and add attachments Pin
Heath Stewart2-Feb-04 5:36
protectorHeath Stewart2-Feb-04 5:36 
GeneralLets start with serious things... Pin
bouli1-Feb-04 23:22
bouli1-Feb-04 23:22 
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 

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.