ctypes 函數指針變量

  • 函數指針作爲參數賦值

    • 案例

      #include<stdio.h>
      void show() {
         printf("%s\n",__FUNCTION__);
      }
      
      void cool(void(**s)()){
         *s = &show;
      }
      ~
      
      
      • 賦值的是show

    • 文件名編譯

      • gcc -fPIC --shared test.c -o test.so

  • python

    • 代碼

      import ctypes
      VOID_T = ctypes.CFUNCTYPE(None)
      t = VOID_T()
      
      handle=ctypes.CDLL("./test.so")
      handle.cool.argtypes=[ctypes.POINTER(VOID_T)]
      handle.cool(ctypes.pointer(t))
      t()
      
      
    • 執行

      • 輸出函數名show.

  • 發表評論
    所有評論
    還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
    相關文章