1

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.