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. 11 2691
On 2005-10-04, Java and Swing <co*******@gmail.com> wrote: Is there some other way, besides SWIG, which will allow me to call functions inside an Ansi C DLL?
ctypes
--
Grant Edwards grante Yow! Now KEN and BARBIE
at are PERMANENTLY ADDICTED to
visi.com MIND-ALTERING DRUGS...
ok i got ctypes...now i try from ctypes import * myApp = CDLL("C:\\myapp.dll")
...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:
Is there some other way, besides SWIG, which will allow me to call functions inside an Ansi C DLL?
ctypes
-- Grant Edwards grante Yow! Now KEN and BARBIE at are PERMANENTLY ADDICTED to visi.com MIND-ALTERING DRUGS...
On 2005-10-04, Java and Swing <co*******@gmail.com> wrote: ok i got ctypes...now i try
from ctypes import * myApp = CDLL("C:\\myapp.dll")
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.
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
Java and Swing wrote: Is there some other way, besides SWIG, which will allow me to call functions inside an Ansi C DLL?
You could write an extension module. See Modules/xxmodule.c in
the Python source tree, as well as http://docs.python.org/ext/ext.html
In the specific case, if it weren't for the digits argument,
the wrapper function would read
static PyObject*
Py_DoSomeStuff(PyObject*unused, PyObject* args)
{
char *input;
if (!PyArg_ParseTuple("s:DoSomeStuff", &input))
return NULL;
return PyString_FromString(DoSomeStuff(input));
}
I cannot extend this to digits, as I don't know how
the digits are represented if there is more than one
(i.e. how does DoSomeStuff know how many digits are
being passed?)
If DoSomeStuff returns NULL on errors, additional
exception throwing is necessary. If DoSomeStuff returns
memory that the caller needs to release, you need to
do so before returning from Py_DoSomeStuff.
Regards,
Martin
I used, myApp = CDLL("C:...") ...as I saw it in one of the ctypes
samples.
Anyhow, I tried...
myApp = cdll.LoadLibrary("C:\\myapp.dll")
myApp.AddNumbers(1, 4)
...I get an error...
AttributeError: function 'AddNumbers' not found
....myapp certainly has AddNumbers.
Grant Edwards wrote: On 2005-10-04, Java and Swing <co*******@gmail.com> wrote: ok i got ctypes...now i try
from ctypes import * myApp = CDLL("C:\\myapp.dll")
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.
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
Java and Swing wrote: I used, myApp = CDLL("C:...") ...as I saw it in one of the ctypes samples.
Anyhow, I tried...
myApp = cdll.LoadLibrary("C:\\myapp.dll") myApp.AddNumbers(1, 4)
..I get an error...
AttributeError: function 'AddNumbers' not found
...myapp certainly has AddNumbers.
properly exported? what does
dumpbin /exports myapp.pyd
say?
</F>
i tried... from ctypes import * myapp = cdll.LoadLibrary("c:\\myapp.dll") dumpbin /exports myapp.pyd
i get, SyntaxError: invalid syntax with it pointing at the first "p" in
myapp.pyd.
On 2005-10-05, Java and Swing <co*******@gmail.com> wrote: i tried...
from ctypes import * myapp = cdll.LoadLibrary("c:\\myapp.dll") dumpbin /exports myapp.pyd
i get, SyntaxError: invalid syntax with it pointing at the first "p" in myapp.pyd.
Um, just a guess, but I don't think that was python code.
Try it at a command prompt.
--
Grant Edwards grante Yow! The entire CHINESE
at WOMEN'S VOLLEYBALL TEAM all
visi.com share ONE personality --
and have since BIRTH!!
"Java and Swing" wrote: from ctypes import * myapp = cdll.LoadLibrary("c:\\myapp.dll") dumpbin /exports myapp.pyd
i get, SyntaxError: invalid syntax with it pointing at the first "p" in myapp.pyd.
dumpbin is a command-line utillity, usually included in the compiler
toolsuite...
</F>
i dont have a myapp.pyd ...i have myapp.c, or are u suggesting I dump
the dll? or the swig generated python file?
the swig generated python file only has .py and .pyc.
"Java and Swing" wrote: i dont have a myapp.pyd ...i have myapp.c, or are u suggesting I dump the dll?
if that's what you're trying to import, yes.
or the swig generated python file? the swig generated python file only has .py and .pyc.
huh? if you have a swig-generated python file, why are you using ctypes?
</F> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Dave Kuhlman |
last post by:
Is JPE (the Python Java Extension) being used widely/actively?
I tried to build it (with Python 2.3.4, j2se 1.4 on Debian
GNU/Linux) and had quite a bit of trouble. And, then, the samples
did...
|
by: sdhyok |
last post by:
PyMat enables to call matlab functions from python.
But, what I want is to call python functions from matlab.
Is there any library for it? Thanks.
Daehyok Shin
|
by: FAN |
last post by:
I want to define some function in python script dynamicly and call
them later, but I get some problem. I have tried the following:
##################################
# code...
|
by: Riko Wichmann |
last post by:
hi everyone,
I'm googeling since some time, but can't find an answer - maybe because
the answer is 'No!'.
Can I call a function in python inline, so that the python byte compiler
does...
|
by: enjoying the view |
last post by:
I am working on a school project, trying to build a simple RPC stub
generator. The idea is that the generator takes a normal python file
with functions defined in it and produces a client and...
|
by: beginner |
last post by:
Hi Everyone,
I have encountered a small problems. How to call module functions
inside class instance functions? For example, calling func1 in func2
resulted in a compiling error.
"my module...
|
by: bappai |
last post by:
Hello,
I am trying to actually call a GUI from my C++ code which would have buttons and therefore can call functions from C++ again, ie extend the C++ code also.
I am faced with a peculiar...
|
by: mh |
last post by:
I'm cleaning up some old code, and want to see what orphan
functions might be sitting around.
Is there a static call tree analyzer for python?
Many TIA!
Mark
--
Mark Harrison
|
by: Astley Le Jasper |
last post by:
Sorry for the numpty question ...
How do you find the reference name of an object?
So if i have this
bob = modulename.objectname()
how do i find that the name is 'bob'
|
by: hofsoc20 |
last post by:
Hi,
I am trying to call a python script (Python 2.5) and implement one of its functions. I have successfully called the script and executed it with jep.runscript("sample.py").
Does anyone...
|
by: Rina0 |
last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
|
by: erikbower65 |
last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps:
1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal.
2. Connect to...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: kcodez |
last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
|
by: Taofi |
last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same
This are my field names
ID, Budgeted, Actual, Status and Differences
...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: lllomh |
last post by:
How does React native implement an English player?
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
| |