I am trying to pass a Python string to a c function (DLL) using ctypes. The function needs a const char*. I am using create_string_buffer, but it returns an error: raise TypeError(init) TypeError:
My python code is quite simple:
testUpdate = myDll['testUpdate']
def testUpdate(Path):
p_path = ctypes.create_string_buffer(Path)
print ctypes.sizeof(p_path), repr(p_path.raw)
print repr(p_path.value)
testUpdate(p_path)
testUpdate.restype = ctypes.c_char
And my C code is even simpler:
char testUpdate(const char* softwareToolsPath){
char p;
p = *softwareToolsPath;
return p;
}
I saw this post: create_string_buffer throwing error TypeError: str/bytes expected instead of str instance But it didn't help. Could anybody help?
I am using python 2.7.
To avoid any confusion, all I'm trying to do is give a Path (using Python) to a DLL. That DLL will open the file pointed by the path and do its magic. So I am simply trying to write a little wrapper for a existing C function.