小编Hel*_*ali的帖子

create_string_buffer抛出错误TypeError:str/bytes而不是str实例

我正在尝试这个简单的ctypes示例并获得提到的错误

>>> from ctypes import create_string_buffer
>>> str = create_string_buffer("hello")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python32\lib\ctypes\__init__.py", line 59, in create_string_buffer
buf.value = init
TypeError: str/bytes expected instead of str instance
Run Code Online (Sandbox Code Playgroud)

有谁知道我做错了什么?

在同一个注释中,我试图从我的python代码将指向字符串的指针传递给C函数,以便我可以在那里执行一些字符串操作并返回另一个字符串.有人可以给我一些关于如何做到这一点的示例代码吗?

extern "C" __declspec(dllexport) char * echo(char* c)
{
      // do stuff
    return c;
}
Run Code Online (Sandbox Code Playgroud)

python string ctypes pointers

13
推荐指数
2
解决办法
1万
查看次数

标签 统计

ctypes ×1

pointers ×1

python ×1

string ×1