title: Python - converting a string object into a ctypes (unsigned char *)
body: <p>I want to use a DLL file with a function that has the following signature - </p>
  
  <pre><code>bool isValid = isImageValid((unsigned char *) buff, const __uint32&amp; buffLen, 
                              int imageW, int imageH, __uint32 requiredSize);
  </code></pre>
  
  <p>Now, buff has to result from a string I'm getting to the python wrapper that is equaivalent to </p>
  
  <pre><code>pyBuff = open(someimagefile, 'rb').read()
  </code></pre>
  
  <p>Since pyBuff is big (mostly), I don't want to allocate a new c uchar array and copy, but to make use of the original buffer. Basically, grab the char buffer of the pyBuff object and reference it as a ctypes (c_ubyte *).</p>
  
  <p>The closest I came to it is:</p>
  
  <pre><code>buff = cast(pyBuff, POINTER(c_ubyte))
  </code></pre>
  
  <p>But I'm not sure this is the type I want. Anyway, the function gives me the following error</p>
  
  <pre><code>WindowsError: exception: access violation writing 0x00000000
  </code></pre>
  
  <p>Will be glad for any help..</p>
  
  <p>Also - two short questions:  </p>
  
  <ol>
  <li><p>Is the following a right definition,given that in an existing C wrapper to this DLL (which I'm working with as a reference) the function that calls (also) this one has the signature: <code>(const char * buff, const __uint32&amp; buffLen)</code></p>
  
  <pre><code>byref(c_ulong(len(pyBuff)) 
  </code></pre></li>
  <li>What's the difference between CDLL and WinDLL, and which is the right one to use?</li>
  </ol>