Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/304.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/60.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
can';t将.dll文件加载到python脚本中_Python_C_Dll - Fatal编程技术网

can';t将.dll文件加载到python脚本中

can';t将.dll文件加载到python脚本中,python,c,dll,Python,C,Dll,我想在windows上从python脚本调用C函数。为此,我在python中包含了C代码的.dll。但它不调用该函数,并且在运行python时并没有显示任何错误 代码:sum.C #include<stdio.h> int our_function(int num_numbers, int numbers) { return num_numbers*numbers; } DLL文件由Cygwin编译器生成 有谁能告诉我这是怎么回事吗?也许你的问题有一些拼写错误 return n

我想在windows上从python脚本调用C函数。为此,我在python中包含了C代码的.dll。但它不调用该函数,并且在运行python时并没有显示任何错误

代码:sum.C

#include<stdio.h>
int our_function(int num_numbers, int numbers)
{
  return num_numbers*numbers;
}
DLL文件由Cygwin编译器生成


有谁能告诉我这是怎么回事吗?

也许你的问题有一些拼写错误

return num_numbers*number; // should be numbers (number is not declared)
Python代码输入错误:

sum = ctypes.cdll.LoadLibrary('C:\Python27\sum.dll')
# should be r'C:\Python27\sum.dll' or 'C:\\Python27\\sum.dll'
并使用明确的cdecl惯例:

int _cdecl our_function(int num_numbers, int numbers)

为什么您仍在使用一个古老的Python版本?错误到底在哪里?错误消息是什么?也就是说,您应该转义应该包含反斜杠的字符串。另外,使用dependencywalker检查DLL导出的符号以及是否满足其依赖关系。请阅读Windows世界中有几种调用约定中的
调用约定,cygwin可能只是使用了您所期望的以外的内容。P.S。在C++文件中使用这个声明:<代码> Extn”C“yOxDeExFc(DLRuturn)int UuSuffic(int NothigNoint,INTION)< /Calp>。C++编译器在二进制文件中为函数名做隐式前缀和后缀,如果未指定“代码”>“外部”“C”/代码>,这只是C代码。Python编译器不识别DLL文件,它不能继续执行Python代码。但还是同样的问题。你能帮我吗?你尝试过显式的cdecl约定吗?没有。你能告诉我如何使用这个约定从python调用C函数吗?可能吗?
int _cdecl our_function(int num_numbers, int numbers)