struct

How to pack and unpack using ctypes (Structure <-> str)

This might be a silly question but I couldn't find a good answer in the docs or anywhere. If I use struct to define a binary structure, the struct has 2 symmetrical methods for serialization and deserialization (pack and unpack) but it seems ctypes doesn't have a straightforward way to do this. Here's my solution, which feels wrong: fr...

How to check programatically if a type is a struct or a class?

I think the question is clear. ...

How to delete structure entries in C

I have a list of structures and I want to delete some of them. I don't want to leave any empty space where the structures are deleted. I tried it with this code, but it didn't work. struct symtab *sp; for(sp = symtab; sp < &symtab[NSYMS]; sp++) if(sp->scope == scope) // delete { sp = sp+1; ...

Unity: Fatal Execution Engine Error when resolving a TimeSpan

I am trying to resolve a TimeSpan using Unity. Executing the container Resolve call results in a FatalExecutionEngineError. FatalExecutionEngineError was detected Message: The runtime has encountered a fatal error. The address of the error was at 0x543c3dc8, on thread 0x1bb8. The error code is 0xc0000005. This error may be a bug i...

Pinning an updateble struct before passing to unmanaged code?

Hi I using some old API and need to pass the a pointer of a struct to unmanaged code that runs asynchronous. In other words, after i passing the struct pointer to the unmanaged code, the unmanaged code copies the pointer and returns immediately. The unmanaged code can access that struct in background, in another thread. I have no contr...

Static struct linker error

I'm trying to create a static struct in C++: static struct Brushes { static HBRUSH white ; static HBRUSH yellow ; } ; But its not working, I'm getting: Error 4 error LNK2001: unresolved external symbol "public: static struct HBRUSH__ * Brushes::white" Why? The idea is to be able to use Brushes::white, Brushes::yellow through...

delphi records and c structs

Task: Application written in Delphi accepts a structure (record in terms of Delphi) of three fields. I can send the pointer of this structure using SendMessage (Win32api) function. So a question is: How to maintain certain structure representation in memory for delphi in terms of delphi. It has type PWPModPostData = ^ TWPModPostDat...

How to copy a char[] in c into my struct

I am trying to send my struct over a UDP socket. struct Packet { int seqnum; char data[BUFFERSIZE]; }; So on the sender I have bytes = sizeof(packet); char sending[bytes]; bzero(sending, bytes); memcpy((void *) sending, (void *) &packet, sizeof(bytes)); bytes = sendto(sockfd, sending, sizeof(sending), 0, (struct sockaddr *...

howto parse struct to C++ dll from C#

I am trying to call a function in a unmanaged C++ dll. It has this prototype: [DllImport("C:\\Program Files\\MySDK\\VSeries.dll", EntryPoint = "BII_Send_Index_Template_MT" )] internal unsafe static extern Int32 BII_Send_Index_Template_MT(IntPtr pUnitHandle, ref BII_Template template, Int32 option, Boolean async); BII_Template tem...

Marshal struct problem with C#

I'm usign C# with P/Invoke to acces to a dll method. The definition of the method is the following: [DllImport("userManager.dll")] static extern int GetUsers(out IntPtr userList); And the struct layout I've done is the following: [StructLayout(LayoutKind.Sequential)] public class USER_LIST { public uint NumUsers; ...

Iterating over same type struct members in C

Is it possible to iterate of a C struct, where all members are of same type, using a pointer. Here's some sample code that does not compile: #include <stdio.h> #include <stdlib.h> typedef struct { int mem1 ; int mem2 ; int mem3 ; int mem4 ; } foo ; void my_func( foo* data ) { int i ; int* tmp = data ; // This ...

struct vs class as STL functor when using not2

Hi. Studing STL I have written a a simple program to test functors and modifiers. My question is about the difference aon using CLASS or STRUCT to write a functor and try to operate on it with function adaptors. As far as I understand in C++ the difference beetween CLASS and STRUCT is that in the last case the members are public by defau...

Iterate Over Struct; Easily Display Struct Fields And Values In a RichEdit Box

Is there an easier way to display the struct fields and their corresponding values in RichEdit control? This is what I am doing now: AnsiString s; s = IntToStr(wfc.fontColor); RichEdit1->Lines->Append(s); etc... Is there an easier way than having to individually call each one? I want to read a binary file and then display the corre...

Why can I assign structs but not compare them

Even though I am a long time C programmer, I only recently learned that one can directly assign structure variables to one another instead of using memcpy: struct MyStruct a,b; ... a = b; /* implicit memcpy */ Though this feels a bit "high-level" for C, it is definitely useful. But why can't I do equality and inequality comparison: i...

Coding problem using a 2-d array of structs inside another struct in C

I am working with a 2-dimensional array of structs which is a part of another struct. It's not something I've done a lot with so I'm having a problem. This function ends up failing after getting to the "test" for-loop near the end. It prints out one line correctly before it seg faults. The parts of my code which read data into a dummy ...

How do I organize this data into stuctures in MATLAB?

Say for n=5, the following code gives me a plot for n randomly generated nodes. These nodes are not structures (just plotted points), but I want to assign every node a message just as I did for sink and source and keep track of the nodes identity and location. For example, if node 4 has (x,y) coordinates (.3452 , .5463), I want to assig...

How do I write a public function to return a head pointer of a linked list?

class Newstring { public: Newstring(); void inputChar ( char); void display (); int length (); void concatenate (char); void concatenate (Newstring); bool substring (Newstring); void createList (); Node * getHead (); // error private: struct Node { char item; Node *next; }; N...

how to assign random energy E to every node and compare two nodes for maximum energy and also find distance between them?

As helped by gnovice I got following code, but now I want to assign energy (randomly) to every nodes using E=floor(rand(1)*10) and also want to compare for maximum energy and what is distance between them? N=input('no. of nodes : '); %# Number of nodes coords = num2cell(rand(N,2)) %# Cell array of random x and y coordin...

sizeof array of structs in C?

In C I have an array of structs defined like: struct D { char *a; char *b; char *c; }; static struct D a[] = { { "1a", "1b", "1c" }, { "2a", "2b", "2c" } }; I would like to determine the number of elements in the array, but sizeof(a) returns an incorrect resu...

Problem assigninging values to a struct in C++ to a structure passed from C#

I have a function in C# that is passing an array of structures into a DLL written in C++. The struct is a group of ints and when I read out the data in the DLL all the values come out fine. However if I try to write to the elements from C++ the values never show up when I try to read then back in C#. C# [StructLayout(LayoutKind.Sequent...