Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ctypes c_char_p作为python函数的输入_Python_C_Dll_Ctypes - Fatal编程技术网

ctypes c_char_p作为python函数的输入

ctypes c_char_p作为python函数的输入,python,c,dll,ctypes,Python,C,Dll,Ctypes,我正在为它编写一个C DLL和一个python脚本,如下所示: //test.c __declspec(dllexport) HRESULT datafromfile(char * filename) { HRESULT errorCode = S_FALSE; if (pFileName == NULL) { return E_INVALIDARG; } FILE *fp = NULL; fopen_s(&fp, pFil

我正在为它编写一个C DLL和一个python脚本,如下所示:

//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....
我编写的python脚本如下所示:

//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)
在调用main时,我将文件名分配为:

FileName = 'abcd.EDID'
datafromfile(FileName)
但是代码给出了一个错误,Windows
error:Unspecified error

有谁能帮我把
c\u char\u p
传递给上面显示的函数吗?

我犯了一个非常愚蠢的错误,我把edid文件保存在其他文件夹中,并从其他文件夹运行脚本。我没有只给出文件名,而是给出了相对路径