Python Forum

Full Version: Error Ctypes in Windows
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello everyone.

I have just begun to program in Python. I have done several scripts and now I am trying to call the Windows API with Ctypes module.

I have copied the example code of the web (docs.python.org\ctypes) but it doesn't run.
from ctypes import *
print windll.kernel32  
It shows the following error:
Error:
"NameError: name 'windll' is not defined"
I have tried with:
  • other DLL (kernel32; msvcrt,...)
  • especify the path (Windows\System32; Windows\SysWOW64)
  • windll, cdll, oledll and dll

I have test others similar examples in Inet, but allways the same error.

I have the 2.7 Python version in Windows 10 .

Have someone any suggestion?.

Thanks a lot.

Regards,
Ric
Suggest upgrade to python 3.6.3
I couldn't install ctypes in 3.6 in my Windows 10, for this reason I downgrade to 2.7.
In this version this module is integrated.
Thanks.
Regards,
Ric
There is no install of ctypes for 3.6 in any version of Python,it's build in.
Test 3.6:
λ ptpython
>>> from ctypes import *

>>> print(windll.kernel32)
<WinDLL 'kernel32', handle 76870000 at 0x3aab750>
>>> print(cdll.msvcrt)
<CDLL 'msvcrt', handle 76950000 at 0x54f9650>
Test 2.7:
λ py -2.7
Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:19:22) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from ctypes import *
>>> print windll.kernel32
<WinDLL 'kernel32', handle 76870000 at 3772370>
How you get NameError on windll,is unclear.
Python 3.6 and pip installation under Windows
Hello snippsat.

I get the same result when run by command line but when I run with Scite it is showed the error.

Thanks.

Regards,
Ric