Click here to Skip to main content
15,888,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a C++ .dll function that I am accessing through python 3.2 with the syntax:

C++
int Create(char argID)

and I am trying to access this function using python. I can access it, but I am confused on why it is telling for 'wrong type' whenever I try to pass the function an argument. Python Script:

Delphi
Create.argtypes = [c_char]
Create.restype = c_int
ID = c_char
ID = input("Enter ID:")
Create(ID) #ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type


Not sure where I am going wrong or is there a different way to pass a character or characters from the user input? Kindly help.

Cheers.
Posted

1 solution

I have been able to figure out the answer, so just posting it for other users if they come across this problem.

SQL
A c_char is a one-byte value, not a Unicode string. Set ID = bytes(ID, 'utf8')[0] (or use a different 8-bit character mapping than 'utf8', such as 'latin-1'). Then you can call Create(ID).

By the way, assigning ID to c_char only gives you another reference to c_char, and then you immediately reassign ID to the returned string from input. The only time I see this is when people are working with ctypes. It's like the brain gets stuck in static typing mode.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900