title: How can I reference a Structure in a Structure using python ctypes
body: <p>Good morning,
  I have been searching for an answer for quite some time. I hope I simply didn't try the wrong key words. Thanks for the answers! Here is my question:</p>
  
  <p>I'm writing some proof of concept code. I have two C structs. StructureA has a pointer to StructureB. The function bar prints the values to the console. The goal is to initialize and use the structs in Python and pass them to a shared lib, which does some fancy stuff with the structs.</p>
  
  <p>I assume I do something wrong in Python. I tried several ways, as you can see in the (Python-)main function.</p>
  
  <p>Additionally the content of the Strings is mixed up, but that is not my major questions.</p>
  
  <p>This is my C code:</p>
  
  <pre><code>#define _DLL_H_ 
  #if BUILDING_DLL 
  # define DLLIMPORT __declspec (dllexport) 
  #else /* Not BUILDING_DLL */ 
  # define DLLIMPORT __declspec (dllimport) 
  #endif /* Not BUILDING_DLL */ 
  
  #include &lt;stdio.h&gt;
  
  #ifdef __cplusplus
  extern "C" {
  #endif
  
  typedef struct StructureB {
      int Value1;
      char Value2[80];
  } StructureB;
  
  typedef struct StructureA {
      int ValueA;
      char ValueB[80];
      StructureB *ValueC;
  } StructureA;
  
  void bar(StructureA *ref){
      printf("ValueA: %d\n", ref-&gt;ValueA);
      printf("ValueB: %s\n", ref-&gt;ValueB);
      printf("Value1: %d\n", ref-&gt;ValueC-&gt;Value1);
      printf("Value2: %s\n", ref-&gt;ValueC-&gt;Value2);
  }
  
  #ifdef __cplusplus
  }
  #endif
  </code></pre>
  
  <p>Here is my Python Code:</p>
  
  <pre><code>#!/usr/bin/python
  
  from ctypes import *
  import sys
  
  class StructureB(Structure):
     _fields_ = [('Value1', c_int),
                 ('Value2', c_char_p)]
  
  class StructureA(Structure):
     _fields_ = [('ValueA', c_int),
                 ('ValueB', c_char_p),
                 ('ValueC', POINTER(StructureB))]
  
  
  def main(argv):
      lib = cdll.LoadLibrary("structures.dll")
  
      sub_struct = StructureB()
      sub_struct.Value1 = 42*42
      sub_struct.Value2 = c_char_p("Hello StructureB!")
  
      struct = StructureA()
      struct.ValueA = -42
      struct.ValueB = c_char_p("Hello StructureA!")
  
      #struct.ValueC = pointer(sub_struct)
      #struct.ValueC = cast(sub_struct, POINTER(StructureB))
      #struct.ValueC = addressof(StructureB)
      #struct.ValueC = pointer(StructureB)
      struct.ValueC = StructureB
  
      lib.bar(pointer(struct))
  
      print sub_struct.Value2
      print struct.ValueB
  
  if __name__ == "__main__":
      main(sys.argv)
  </code></pre>