R
R
Rudtoha2017-01-31 01:33:21
Python
Rudtoha, 2017-01-31 01:33:21

How to fix error when connecting Dll python?

Good day, I ran into the following problem: When calling a function from a dll written in C, python gets the following error: argument 1: : wrong type (code below)

import ctypes
from ctypes import *

CanApiDll = cdll.vs_can_api

handle = "12345"
U_Handle = handle.encode('utf-8')
DevHandle = c_char_p(U_Handle)

Mode = c_ulong(0)

PrototypeOpen = WINFUNCTYPE(c_int, c_char_p, c_ulong)   # c_char_p -> c_wchar_p
VSCanOpenParam = (1, "DevHandle", 0), (1, "Mode", 0)
VSCanOpen = PrototypeOpen(("VSCAN_Open", CanApiDll), VSCanOpenParam)
VSCanOpen(ctypes.byref(DevHandle), Mode)

At first I thought that the error lies in the call to c_char_p and decided to try a function that accepts only c_int:
N = c_int(1)

PrototypeClose = WINFUNCTYPE(c_int, c_int)
VSCanCloseParam = (1, "DevHandle", 0),
VSCanClose = PrototypeClose(("VSCAN_Close" , CanApiDll), VSCanCloseParam)

VSCanClose(N)

But another error appears, which looks like this: Procedure probably called with too many arguments (4 bytes in excess)
Googling did not help much, so I would be very grateful if you could help)
Thanks in advance)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
NaName, 2017-01-31
@Rudtoha

def testImportMean():
    tmp_dll = cdll.LoadLibrary("/home/nick/python/dllTests/libmean.so")

    summ = 0
    for i in range(0, 1000):
        for j in range(0, 1000):
            summ += tmp_dll.mean(c_int(i), c_int(j))

    return summ

I have a test call like this. you probably have an error in what to transfer to C you need not int-python, but c_int

S
serf10, 2018-04-23
@serf10

Same problem, how should it be in the end? And is there somewhere a ready-made wrapper code for the VSCOM adapter in python?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question