Python Forum
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error Ctypes in Windows
#1
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
Reply
#2
Suggest upgrade to python 3.6.3
Reply
#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
Reply
#4
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
Reply
#5
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  using ctypes to use a dll in a python module dauriac 3 368 Mar-06-2024, 04:38 PM
Last Post: dauriac
  Trying to debug segfault in ctypes binding to Fortran bthomas 1 590 Sep-01-2023, 11:26 AM
Last Post: bthomas
  ctypes juliolop 7 1,383 Apr-20-2023, 03:33 PM
Last Post: Larz60+
  "SSL: CERTIFICATE_VERIFY_FAILED” error on Python 3.9.6 (Windows 10) rcmv 4 3,660 May-10-2022, 01:18 PM
Last Post: rcmv
  Issue while using ctypes in python GiggsB 6 2,755 Mar-27-2022, 03:38 AM
Last Post: GiggsB
  Ctypes and libffi.so.7 luxedo 1 6,044 Oct-23-2021, 09:24 PM
Last Post: DeaD_EyE
  error while installing any library using pip in windows AkashKansal 1 4,394 Sep-24-2020, 07:51 AM
Last Post: buran
  Correct py got error on another windows 7 meetinnet 8 3,850 Apr-25-2020, 04:57 PM
Last Post: meetinnet
  possible ctypes and numpy conflict? herbal_rage 0 3,140 Apr-16-2020, 11:35 AM
Last Post: herbal_rage
  Python 3.7, Windows 7, Syntax Error hughdent 1 2,274 Mar-23-2020, 10:09 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020