从Python调用C函数 [英] Call C functions from Python
问题描述
还有其他一些方法,除了SWIG,它允许我在Ansi C DLL中调用
函数吗?
示例(C):
defs.h
-------
typedef unsigned long MY_DIGIT;
myapp.c
-----------------
#include" defs.h"
char * DoSomeStuff(字符*输入,MY_DIGIT *位数){
...
}
...这就是我想用Python调用的一个例子。
Is there some other way, besides SWIG, which will allow me to call
functions inside an Ansi C DLL?
Example (C):
defs.h
-------
typedef unsigned long MY_DIGIT;
myapp.c
-----------------
#include "defs.h"
char *DoSomeStuff(char *input, MY_DIGIT *digits) {
...
}
...thats an example of something I would like to call from Python.
推荐答案
2005-10-04, Java和Swing< co ******* @ gmail.com>写道:
On 2005-10-04, Java and Swing <co*******@gmail.com> wrote:
还有其他一些方法,除了SWIG,它允许我在Ansi C DLL中调用
函数吗?
Is there some other way, besides SWIG, which will allow me to call
functions inside an Ansi C DLL?
ctypes
-
格兰特爱德华兹格兰特哇!现在KEN和BARBIE
非常适合
visi.com改变药物......
ctypes
--
Grant Edwards grante Yow! Now KEN and BARBIE
at are PERMANENTLY ADDICTED to
visi.com MIND-ALTERING DRUGS...
好吧,我得到了ctypes ...现在我尝试从ctypes import中获取
ok i got ctypes...now i try
*
myApp = CDLL(" C:\\ myapp.dll")
from ctypes import *
myApp = CDLL("C:\\myapp.dll")
...现在如何在myapp.dll中调用函数?从教程我是
不确定..我试试,dir(cdll.myApp)和dir(myApp)..但是没有看到我列出的
功能。
谢谢
Grant Edwards写道:2005-10-04,Java和Swing< co ******* @ gmail.com>写道:
...now how can I call functions on in myapp.dll? From the tutorial I am
not sure..i try, dir(cdll.myApp) and dir(myApp)..but don''t see my
functions listed.
thanks
Grant Edwards wrote: On 2005-10-04, Java and Swing <co*******@gmail.com> wrote:
还有其他一些方法,除了SWIG,它允许我在Ansi C DLL中调用
函数吗?
Is there some other way, besides SWIG, which will allow me to call
functions inside an Ansi C DLL?
ctypes
- 格兰特爱德华兹格兰特哇!现在,KEN和BARBIE一直非常喜欢
visi.com MIND-ALTERING DRUGS ......
ctypes
--
Grant Edwards grante Yow! Now KEN and BARBIE
at are PERMANENTLY ADDICTED to
visi.com MIND-ALTERING DRUGS...
2005-10-04,Java和Swing< co ******* @ gmail.com>写道:
On 2005-10-04, Java and Swing <co*******@gmail.com> wrote:
好吧我有ctypes ...现在我尝试
ok i got ctypes...now i try
来自ctypes import *
myApp = CDLL(C:\\ myapp.dll)
from ctypes import *
myApp = CDLL("C:\\myapp.dll")
我之前从未见过这种用法。我不知道CDLL会做什么,而且我无法在任何地方的文档中找到它。
基于我对教程的阅读,我会尝试eitehr
myApp = cdll.myapp
或
myApp = cdll.LoadLibrary(" C: /myapp.dll")
..现在如何在myapp.dll中调用函数?从
教程我不确定..
假设CDLL做了相当于cdll.LoadLibrary()的事情,
我会试试:
myApp.FuncName()
我一直都是按照教程中的方式完成的:
mylib = windll.Lib_Name
mylib.myFuncName()
i try,dir(cdll.myApp)和dir(myApp)。但是我没有看到列出我的
功能。
I''ve never seen that sort of usage before. I don''t know what
CDLL does, and I can''t find it in the docs anywhere.
Based on my reading of the tutorial, I would have tried eitehr
myApp = cdll.myapp
or
myApp = cdll.LoadLibrary("C:/myapp.dll")
..now how can I call functions on in myapp.dll? From the
tutorial I am not sure..
Assuming CDLL did something equivalent to cdll.LoadLibrary(),
I''d try:
myApp.FuncName()
I''ve always done it the way it''s done in the tutorial:
mylib = windll.Lib_Name
mylib.myFuncName()
i try, dir(cdll.myApp) and dir(myApp)..but don''t see my
functions listed.
我不认为dir()在dll上运行就像那样。我当然
在教程中没有看到它。你怎么回事?
尝试按照教程的方式调用函数?
myapp = cdll.myapp
myapp.MyFunc ()
-
格兰特爱德华兹格兰特哇!佑!在我的防护白蚁证明上是否有我的余额
?
visi.com
I don''t think dir() works on dll''s like that. I certainly
don''t see it mentioned in the tutorial. What happened when you
tried calling the function the way the tutorial does?
myapp = cdll.myapp
myapp.MyFunc()
--
Grant Edwards grante Yow! Yow! Is my fallout
at shelter termite proof?
visi.com
这篇关于从Python调用C函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!