Reputation: 25
I am writing a C DLL and a python script for it as below:
//test.c
__declspec(dllexport) HRESULT datafromfile(char * filename)
{
HRESULT errorCode = S_FALSE;
if (pFileName == NULL)
{
return E_INVALIDARG;
}
FILE *fp = NULL;
fopen_s(&fp, pFileName, "rb");
if (fp == NULL)
return E_FAIL;
some more lines of code are there....
The python script that i had written is as follows:
//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)
While calling in the main I'm assigning the filename as:
FileName = 'abcd.EDID'
datafromfile(FileName)
But the code is giving an error, Windows Error: Unspecified Error
.
Can anybody help me in how to pass the c_char_p
to the function as shown above?
Upvotes: 1
Views: 144
Reputation: 25
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.
Upvotes: 1