Calling foreign functions from Python? ctypes?

P

Paul Watson

I need to call some Windows APIs. Is the only way to download ctypes or
the win32 interfaces? Is there any plan to get ctypes batteries into
the standard Python build?
 
G

Guest

Paul said:
I need to call some Windows APIs. Is the only way to download ctypes or
the win32 interfaces?

That depends on the specific win32 interface you want to call.
Typically, the answer is "yes".
Is there any plan to get ctypes batteries into the standard Python build?

I don't have such a plan. To my knowledge, ctypes has never been
contributed to Python, either, so its author apparently has no plan,
either.

Regards,
Martin
 
N

Neil Hodgson

Paul Watson:
Is there any plan to get ctypes batteries into
the standard Python build?

It is unlikely that ctypes will be included in the standard Python
build as it allows unsafe memory access making it much easier to crash
Python.

Neil
 
P

Paul Rubin

Martin v. Löwis said:
To my knowledge, ctypes has never been contributed to Python,
either, so its author apparently has no plan, either.

Has anyone from Python.org asked him or her?
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

Paul said:
Has anyone from Python.org asked him or her?

I can't answer that question. I haven't (and I personally
share Neil Hodgson's reservation wrt. to the possibility
of crashing the interpreter).

Regards,
Martin
 
P

Paul Watson

Neil said:
Paul Watson:



It is unlikely that ctypes will be included in the standard Python
build as it allows unsafe memory access making it much easier to crash
Python.

Does extending Python with any C/C++ function not do the same thing?
 
P

Paul Watson

Martin said:
That depends on the specific win32 interface you want to call.
Typically, the answer is "yes".

I have used _winreg and I see winsound in the doc.

I need to call GetVersionInfo() and handle VERSIONINFO information. I
thought that distutils might have something, but I do not see it yet.
Any suggestions?
 
N

Neil Hodgson

Paul Watson:
Does extending Python with any C/C++ function not do the same thing?

No. It is the responsibility of the extension author to ensure that
there is no possibility of crashing Python. With ctypes, you have a
generic mechanism that enables Python code to cause a crash.

Neil
 
G

Guest

Paul said:
I need to call GetVersionInfo() and handle VERSIONINFO information. I
thought that distutils might have something, but I do not see it yet.
Any suggestions?

You could write this specific API in VB, and then run cscript.exe in
a pipe; or you could write a wrapper module just for that specific
API (in case PythonWin is too large for you).

Regards,
Martin
 
C

Carl Friedrich Bolz

Jean-Paul Calderone said:
I could probably dig up a few more, if you want. So what's ctypes on top of this?

another one:

cfbolz@gauss:~$ python
Python 2.4.2 (#2, Sep 30 2005, 21:19:01)
[GCC 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu8)] on linux2
Type "help", "copyright", "credits" or "license" for more information..... def __del__(self):
.... global ref
.... ref = weakref.ref(self)
........ w = Target()
.... w = None
.... print ref()
....Segmentation fault

There are dozends of segfaults in Python indeed.

Cheers,

Carl Friedrich Bolz
 
P

Paul Watson

Martin said:
You could write this specific API in VB, and then run cscript.exe in
a pipe; or you could write a wrapper module just for that specific
API (in case PythonWin is too large for you).

I cannot find any way to get to GetVersionInfo in VBScript (cscript).

If so, this appears to leave me with no choice but to produce a Windows
executable, whether a .exe or C code wrapped from Python. Right?
 
T

Thomas Heller

=?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= said:
That depends on the specific win32 interface you want to call.
Typically, the answer is "yes".


I don't have such a plan. To my knowledge, ctypes has never been
contributed to Python, either, so its author apparently has no plan,
either.

As the author, I would be happy to see ctypes included with the standard
Python build.

Thomas
 
N

Neil Hodgson

Paul Watson:
I cannot find any way to get to GetVersionInfo in VBScript (cscript).

Set objFSO = CreateObject("Scripting.FileSystemObject")
Wscript.Echo objFSO.GetFileVersion("c:\bin\SciLexer.dll")

Neil
 
P

Paul Watson

Neil said:
Paul Watson:



Set objFSO = CreateObject("Scripting.FileSystemObject")
Wscript.Echo objFSO.GetFileVersion("c:\bin\SciLexer.dll")

Many thanks. Just what I needed. (Short of ctypes.) Thank you for
tolerating a VBScript question here.
 
Z

Ziga Seilnacht

Paul Watson wrote:
..
..
..
I need to call GetVersionInfo() and handle VERSIONINFO information. I
thought that distutils might have something, but I do not see it yet.
Any suggestions?

This information is provided with sys.getwindowsversion().
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top