C的代码

void test_cref(char *a, int *b, char *data)
{
    char *p = (char*)wtk_calloc(20, sizeof(char));
    strcpy(p, "cute");
    a[0] = p[2];

    *b = 223;

    data = a;
    
    wtk_debug("%s %d %s\n", a, *b, data);
}

打包成动态库之后

from ctypes import *

libc = cdll.LoadLibrary("./libwtkdlg.so")

a = create_string_buffer("t".encode("utf-8"))

b = c_int(23)

d = create_string_buffer("douzi".encode('utf-8'))

print(a.value)
print(b.value)
print(d.value)

libc.test_cref(byref(a), byref(b), byref(d))

Python利用ctypes实现按引用传参

Python利用ctypes实现按引用传参

a改变了内容,没有改变指向,b改变了内容

更多: https://www.cnblogs.com/gaowengang/p/7919219.html

相关文章:

  • 2021-05-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-05-11
  • 2021-09-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案