codingdir logo sitemap sitemap |

Interoperability c c# struct sequence

By : , Category : c#

Thanks to shambulator's link i have realized the error was indeed in [,] mat attribute. It should be declared as [MarshallAs(UnmanagedType.ByValArray, SizeConst = 25)] 25 Is the rows multiply with columns - mat [5,5].

ReLated :

Maybe it can work for the base class. But that is on very special case:

  • POD struct
  • same packing
  • same runtime if you allocate/deallocate in C and C++
  • pure C syntax
  • etc...

But it will never directly for the derived class.

But that create so many restriction that I would provide a C level API to allocate an manipulate those pointers defined as alias on "void*" (I'm not even sure you can do such aliases this in pure C).

Something like:

 typedef void* BaseStructPtr;

 BaseStructPtr AllocateBase(/* constructor params */);
 BaseStructPtr AllocateDerived(/* constructor params */);

 TypeOfField1 GetField1(BaseStructPtr ptr);
 TypeOfField2 GetField2(BaseStructPtr ptr);

 /* etc... */

Not sure it's the only problem, but aes_context is declared to contain a pointer, rk;

typedef struct
    int nr;                     /*!<  number of rounds  */
    unsigned long *rk;          /*!<  AES round keys    */
    unsigned long buf[68];      /*!<  unaligned data    */

...that is set by (for example) aes_setkey_enc to point to an address insinde buf inside the same context;

ctx->rk = RK = ctx->buf;

If - between that pointer set and your pinning the pointer - the context memory block is moved in memory, ctx->rk will point to unallocated memory.

I suspect making m_Context a pinned pointer to keep it permanently pinned instead of pinning it temporarily for each call would make the program run successfully.

first: bottom pointer in the seq_struct should be initiated to NULL

second: before calling

seq->bottom = endq;

you have to check if seq->bottom is not NULL. so your code should looks like this

if (seq->bottom != NULL)
seq->bottom = endq;

You have to take in account the first element to insert in your linked list with your function seq_add_back().

So you have to update your seq->bottom also if it's the first elemenent to insert in the linked list.

The seq->bottom should be initiated to NULL.

and you have to add the following code at the end of your function seq_add_back():

if (seq->top == NULL)
    seq->top = endq;

So as summary your function should look like this:

void seq_add_back(Seq seq, ETYPE val){
   NODE* endq = malloc(sizeof(NODE));
   endq->next =NULL;

   endq->prev = seq->bottom;
   endq->data = val;

   if (seq->bottom != NULL)
   seq->bottom = endq;

   if (seq->top == NULL)
      seq->top = endq;


You can use xml:",any" tag on your root node and then unmarshal the rest into structs that have an XMLName field like this:

type RootNode struct {
    Elements []Element `xml:",any"`

type Element struct {
    XMLName xml.Name

More on xml:",any" and XMLName here.

Playground example:


Message :
Login to Add Your Comments .
How to disable registered OpenCL platforms on Windows?
Is Observable broken in Angular 2 Beta 3?
Cross-thread operation not valid when using Invoke
How to pass an IEnumerable or queryable list of properties from Controller to View
Finding numbers after a certain keyword using Python
Pocketsphinx recognizes random phrases in a silence
Passing non-thread-safe objects through thread-safe containers
React scroll nav
BizTalk WCF-BasicHttp Adapter does not allow Empty string for Service Certificate Props
Why property ''cause" of Exception is repeating forever?
Privacy Policy 2017 © All Rights Reserved .