ctypes c_char_p as an input to a function in python
<p>I am writing a C DLL and a python script for it as below:</p>

<pre><code>//test.c
__declspec(dllexport) HRESULT datafromfile(char * filename)
{
  HRESULT errorCode = S_FALSE;

    if (pFileName == NULL)
    {
        return E_INVALIDARG;
    }

    FILE *fp = NULL;
    fopen_s(&amp;fp, pFileName, "rb");

    if (fp == NULL)
        return E_FAIL;

some more lines of code are there....
</code></pre>

<p>The python script that i had written is as follows:</p>

<pre><code>//test.py
import sys
import ctypes
from ctypes import *

def datafromfile(self,FileName):
    self.mydll=CDLL('test.dll')
    self.mydll.datafromfile.argtypes = [c_char_p]
    self.mydll.datafromfile.restypes = HRESULT
    self.mydll.datafromfile(FileName)
</code></pre>

<p>While calling in the main I'm assigning the filename as:</p>

<pre><code>FileName = 'abcd.EDID'
datafromfile(FileName)
</code></pre>

<p>But the code is giving an error, Windows <code>Error: Unspecified Error</code>.
Can anybody help me in how to pass the <code>c_char_p</code> to the function as shown above?</p>

<p>A very silly mistake I was doing, I had kept the edid file in some other folder and was running the script from other. Instead of giving only the filename, I gave the relative path.</p>

python c dll ctypes