Click here to Skip to main content
15,898,035 members
Home / Discussions / C#
   

C#

 
AnswerRe: Controlling a Parallel Port Pin
PIEBALDconsult9-Oct-10 14:52
mvePIEBALDconsult9-Oct-10 14:52 
QuestionHighscore Pin
SRJ929-Oct-10 9:35
SRJ929-Oct-10 9:35 
AnswerRe: Highscore Pin
PIEBALDconsult9-Oct-10 9:40
mvePIEBALDconsult9-Oct-10 9:40 
JokeRe: Highscore Pin
dan!sh 9-Oct-10 10:32
professional dan!sh 9-Oct-10 10:32 
GeneralRe: Highscore Pin
PIEBALDconsult9-Oct-10 15:53
mvePIEBALDconsult9-Oct-10 15:53 
AnswerRe: Highscore Pin
Abhinav S9-Oct-10 17:44
Abhinav S9-Oct-10 17:44 
AnswerRe: Highscore Pin
Richard MacCutchan9-Oct-10 21:49
mveRichard MacCutchan9-Oct-10 21:49 
QuestionMarshalling a structure to contain an array whose length is an earlier struct member? Pin
o m n i9-Oct-10 9:33
o m n i9-Oct-10 9:33 
For loading a file that was originally written by an application written in C++, I have been declaring each part of the file as a struct, and converting the data into a struct using this function:

public static TStruct GetStruct<TStruct>(byte[] data,Type t)
      where TStruct : new()
    {
      int structSize = Marshal.SizeOf(typeof(TStruct));
      TStruct outstruct = new TStruct();
      GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);
      outstruct = (TStruct)Marshal.PtrToStructure(handle.AddrOfPinnedObject(),t);
      handle.Free();
      return outstruct;
    }

This works fine for structs that do not contain arrays or that contain only arrays that can be defined using fixed (eg fixed int someVariable[10]; works fine) ,but I run into a problem when I want to do this to a struct such as:

struct Foobar
{
int count;
customStructType someStruct[count];
}


I've tried using [MarshalAs(UnmanagedType.<tried all these>, <parameters specified type takes here>)] but it either requires me to specify a fixed number upfront or causes my GetStruct method to give me an error that it "could not meaningfully obtain the size of the struct". LPArray allowed me to specify a particular element in the struct that acts as the number of elements in the array but that gave me the aforementioned lack of meaningful size error. Is there any way to make this work?
AnswerRe: Marshalling a structure to contain an array whose length is an earlier struct member? Pin
OriginalGriff10-Oct-10 0:19
mveOriginalGriff10-Oct-10 0:19 
QuestionAn attempt was made to access the socket in a way forbidden by its access permissions Pin
ars.029-Oct-10 8:02
ars.029-Oct-10 8:02 
AnswerRe: An attempt was made to access the socket in a way forbidden by its access permissions Pin
Richard MacCutchan9-Oct-10 21:47
mveRichard MacCutchan9-Oct-10 21:47 
AnswerRe: An attempt was made to access the socket in a way forbidden by its access permissions Pin
Dave Kreskowiak10-Oct-10 3:19
mveDave Kreskowiak10-Oct-10 3:19 
QuestionA question on wcf and composite objects Pin
Michael Eber9-Oct-10 7:20
Michael Eber9-Oct-10 7:20 
Questionwhich way better for activation? Pin
Jassim Rahma9-Oct-10 5:21
Jassim Rahma9-Oct-10 5:21 
AnswerRe: which way better for activation? PinPopular
DaveAuld9-Oct-10 6:04
professionalDaveAuld9-Oct-10 6:04 
GeneralRe: which way better for activation? Pin
OriginalGriff9-Oct-10 6:15
mveOriginalGriff9-Oct-10 6:15 
GeneralRe: which way better for activation? Pin
Luc Pattyn9-Oct-10 7:13
sitebuilderLuc Pattyn9-Oct-10 7:13 
GeneralRe: which way better for activation? Pin
OriginalGriff9-Oct-10 7:16
mveOriginalGriff9-Oct-10 7:16 
AnswerRe: which way better for activation? Pin
OriginalGriff9-Oct-10 6:19
mveOriginalGriff9-Oct-10 6:19 
QuestionAssign By Reference Pin
thenutz729-Oct-10 4:08
thenutz729-Oct-10 4:08 
AnswerRe: Assign By Reference Pin
PIEBALDconsult9-Oct-10 4:18
mvePIEBALDconsult9-Oct-10 4:18 
GeneralRe: Assign By Reference Pin
harold aptroot9-Oct-10 4:45
harold aptroot9-Oct-10 4:45 
AnswerRe: Assign By Reference [modified] Pin
Keith Barrow9-Oct-10 6:28
professionalKeith Barrow9-Oct-10 6:28 
GeneralRe: Assign By Reference Pin
thenutz729-Oct-10 8:45
thenutz729-Oct-10 8:45 
GeneralRe: Assign By Reference Pin
PIEBALDconsult9-Oct-10 9:07
mvePIEBALDconsult9-Oct-10 9:07 

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.