# ImportError: cannot import name WINFUNCTYPE

**URL:** <https://forum.inductiveautomation.com/t/importerror-cannot-import-name-winfunctype/49124>\
**Category:** Ignition\
**Tags:** python, perspective, scripting\
**Created:** [July 23, 2021, 5:44am UTC](https://forum.inductiveautomation.com/t/importerror-cannot-import-name-winfunctype/49124 "2021-07-23T05:44:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![himanshu.choubisa](https://avatars.discourse-cdn.com/v4/letter/h/bb73d2/32.png) [@himanshu.choubisa](https://forum.inductiveautomation.com/u/himanshu.choubisa)\
**Post date:** [July 23, 2021, 5:44am UTC](https://forum.inductiveautomation.com/t/importerror-cannot-import-name-winfunctype/49124/1 "2021-07-23T05:44:09Z")

</div>

Hi all,  
I am new to Ignition Perspective and I am using a 8.1.1 version. I am trying to extract information from a windows file and convert it into the ASCII but when I am running the code I am repeatedly having this error. Please give your inputs for below code:

from ctypes import POINTER, WINFUNCTYPE, c\_char\_p, c\_void\_p, c\_int, c\_ulong, c\_char\_p  
from ctypes.wintypes import BOOL, DWORD, BYTE, INT, LPCWSTR, UINT, LONG, ULONG, LPCSTR, PCHAR, PWCHAR  
import ctypes  
from ctypes import byref  
import sys  
import os, glob

tcAccessDll = r"C:\Users\himanshu.choubisa\Desktop\TcAccess.dll"  
rstfilename = b"C:\Users\himanshu.choubisa\Desktop\RA03534 AGAS UK 70+4min 130521B.rst"

#check newest results file 🙂  
#rstfilename = min(glob.iglob('C:\TCData\Data\*.rst'), key=os.path.getctime).encode('ascii')

# Load DLL into memory.

#hllDll = ctypes.WinDLL (r"c:\PenExe\TcWS\Ver6.3.4\Bin\TcAccess.dll")#

#hllDll = ctypes.cdll.LoadLibrary (r"c:\PenExe\TcWS\Ver6.3.4\Bin\TcAccess.dll")

#hllDll = ctypes.WinDLL (r"c:/PenExe/TcWS/Ver6.3.4/Bin/TcAccess.dll")

#hllDll = ctypes.WinDLL ("TcAccess.dll")

def get\_winfunc(libname, funcname, restype=None, argtypes=(), \_libcache={}):  
"""Retrieve a function from a library, and set the data types."""  
from ctypes import windll

```
if libname not in _libcache:
    _libcache[libname] = ctypes.cdll.LoadLibrary(libname)
func = getattr(_libcache[libname], funcname)
func.argtypes = argtypes
func.restype = restype

return func

```

class TCAccess(object):  
Init = get\_winfunc(tcAccessDll, "TcAccessInit")  
LoggedIn = get\_winfunc(tcAccessDll,"TcAccessLoggedOn", BOOL)  
OpenConversation = get\_winfunc(tcAccessDll, "TcAccessOpenConversation",LONG,[LPCSTR])  
CloseConversation = get\_winfunc(tcAccessDll, "TcAccessCloseConversation", INT, [INT])  
Set = get\_winfunc(tcAccessDll, "TcAccessSet", INT, [INT,LPCSTR,LPCSTR])  
Get = get\_winfunc(tcAccessDll, "TcAccessGet", LPCSTR, [INT, LPCSTR])

print(TCAccess.Init())  
print(TCAccess.LoggedIn())  
topic = 'RST'  
c=(TCAccess.OpenConversation(b"RST"))  
print(c)  
print(TCAccess.Set(c,b"RST\_FILE\_NAME",rstfilename))  
peakcount = int((TCAccess.Get(c,b"Rst\_Num\_Peaks")))  
for index in range(peakcount):  
(TCAccess.Set(c,b"RST\_COMP\_INDEX",str(index).encode('ascii')))  
CompName=(TCAccess.Get(c,b"CP\_COMP\_NAME").decode())  
(TCAccess.Get(c,b"CP\_PEAK\_VECTOR"))  
(TCAccess.Get(c,b"RST\_PEAK\_INDEX"))  
CompArea=(TCAccess.Get(c,b"PK\_AREA\_PCT").decode())  
CompResult=(TCAccess.Get(c,b"PK\_RESULT").decode())  
print ("Component " + CompName + " Peak Area %: " + CompArea + " Peak Concentration: " + CompResult)

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [July 23, 2021, 11:43am UTC](https://forum.inductiveautomation.com/t/importerror-cannot-import-name-winfunctype/49124/2 "2021-07-23T11:43:17Z")

</div>

Jython’s ctypes implementation is incomplete.

Generally, you should not expect to be able to load DLLs or C libraries with Jython nor do Python libraries that wrap C libraries work inside Ignition.

---

<div class="post-metadata">

**Author:** ![himanshu.choubisa](https://avatars.discourse-cdn.com/v4/letter/h/bb73d2/32.png) [@himanshu.choubisa](https://forum.inductiveautomation.com/u/himanshu.choubisa)\
**Post date:** [July 26, 2021, 1:21am UTC](https://forum.inductiveautomation.com/t/importerror-cannot-import-name-winfunctype/49124/3 "2021-07-26T01:21:04Z")

</div>

Thanks Kevin for your inputs  
however, I cant work out how to have the correct implementation of ctypes.  
Will you please elaborate with the correct code?  
Thanks in advance

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 26, 2021, 1:28am UTC](https://forum.inductiveautomation.com/t/importerror-cannot-import-name-winfunctype/49124/4 "2021-07-26T01:28:26Z")

</div>

There is no correct code. You cannot access .DLL files from jython or java. You would need to write another C layer with JNA to access the DLL for you, and wrap it in a java class. Then import that from jython.

It would probably be simpler to write a webservice in CPython to use the existing code, and make requests from Ignition to the webservice.
