title: Passing pointer to pointer to buffer in ctypes
body: <p>I'm trying to grab image data from a camera using ctypes and python. </p>
  
  <p>Very basically, the documentation says that I should connect to the device, set resolution, output window, frame rate and trigger mode (all, apparently successful). Then, I should open an image sequence, and either start grabbing frames, or trigger the camera at moments when I want to get a frame. This is all reasonably clear. Where things start to go wrong is in accessing the frame data. In C, the code should look something like this:</p>
  
  <pre><code>// Snap two images into buffers
  // Buffer size is decided by image resolution
  // Here assuming a image is 800*600
  BeginHVDevice(1,&amp;hDevice1); //Initialize camera 1
  HVSetOutputWindow(hDevice1, 0, 0, 800, 600);
  //bunch of other settings as well
  
  
  BYTE Buffer1[800 * 600]; // Buffer for one image
  BYTE Buffer2[800 * 600]; // Buffer for a second image 
  BYTE *ppBuffer[2]; //This array keeps the pointer to each buffer 
  ppBuffer[0] = Buffer1;
  ppBuffer[1] = Buffer2;
  void *nParam
  long *callBack
  
  HVOpenSnap(hDevice1, callBack, nParam); //note that I don't use call backs so the last two params are not used 
  HVSnapShot(hhv, ppBuffer, 2); //last argument is just the number of frames to collect
  HVCloseSnap(hhv);
  </code></pre>
  
  <p>The problem is the buffer used to store the data. I've tried creating a string buffer of the correct size and passing that byref. I've tried creating integer buffers, long buffers. I get three results: the buffer is never touched (all null values), the program hard crashes and has to restarted (I would guess that python tries to write to an invalid address at this point), or there is a type error.</p>
  
  <p>The current python code looks like this</p>
  
  <pre><code>ailt_lib = WinDLL("HVDAILT")
  util_lib = WinDLL("HVUtil")
  raw_2_rgb_lib = WinDLL("Raw2Rgb")
  
  
  open_snap = ailt_lib.HVOpenSnap
  open_snap.restype = c_int
  open_snap.argtypes = [HANDLE, POINTER(c_long), c_void_p]
  
  close_snap = ailt_lib.HVCloseSnap
  close_snap.restype = c_int
  close_snap.argtypes = [HANDLE]
  
  
  stop_snap = ailt_lib.HVStopSnap
  stop_snap.restype = c_int
  stop_snap.argtypes = [HANDLE,]
  
  start_snap = ailt_lib.HVStartSnap
  start_snap.restype = c_int
  start_snap.argtypes = [HANDLE, POINTER(c_char_p*buf_size), c_int]
  
  click = ailt_lib.HVTriggerShot
  click.restype = c_int
  click.argtype = [POINTER(HANDLE),]
  
  #Bunch of code to initialise the camera. All apparently succeeds
  
  print open_snap(cam_handle, byref(c_long(0)), c_void_p(None))
  storage = c_char_p*buf_size
  buf = storage()
  storage_ptr = pointer(buf)
  print start_snap(cam_handle, storage_ptr, 1)
  print click(cam_handle)
  </code></pre>
  
  <p>I think, in this case, the problem is that I simply don't know how to generate the correct form of buffer that should be passed to start_snap.</p>