久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <small id='jvVce'></small><noframes id='jvVce'>

      <i id='jvVce'><tr id='jvVce'><dt id='jvVce'><q id='jvVce'><span id='jvVce'><b id='jvVce'><form id='jvVce'><ins id='jvVce'></ins><ul id='jvVce'></ul><sub id='jvVce'></sub></form><legend id='jvVce'></legend><bdo id='jvVce'><pre id='jvVce'><center id='jvVce'></center></pre></bdo></b><th id='jvVce'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='jvVce'><tfoot id='jvVce'></tfoot><dl id='jvVce'><fieldset id='jvVce'></fieldset></dl></div>

          <bdo id='jvVce'></bdo><ul id='jvVce'></ul>

        <legend id='jvVce'><style id='jvVce'><dir id='jvVce'><q id='jvVce'></q></dir></style></legend>
      1. <tfoot id='jvVce'></tfoot>
      2. 如何在ctypes中傳回指針?

        How to pass pointer back in ctypes?(如何在ctypes中傳回指針?)
            <i id='tYy8L'><tr id='tYy8L'><dt id='tYy8L'><q id='tYy8L'><span id='tYy8L'><b id='tYy8L'><form id='tYy8L'><ins id='tYy8L'></ins><ul id='tYy8L'></ul><sub id='tYy8L'></sub></form><legend id='tYy8L'></legend><bdo id='tYy8L'><pre id='tYy8L'><center id='tYy8L'></center></pre></bdo></b><th id='tYy8L'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='tYy8L'><tfoot id='tYy8L'></tfoot><dl id='tYy8L'><fieldset id='tYy8L'></fieldset></dl></div>
              <tbody id='tYy8L'></tbody>
              <bdo id='tYy8L'></bdo><ul id='tYy8L'></ul>
              <legend id='tYy8L'><style id='tYy8L'><dir id='tYy8L'><q id='tYy8L'></q></dir></style></legend>
                • <tfoot id='tYy8L'></tfoot>
                • <small id='tYy8L'></small><noframes id='tYy8L'>

                  本文介紹了如何在ctypes中傳回指針?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  對ctypes了解不多,最近才開始接觸.

                  Don't know much about ctypes, just recently began working with it.

                  我在類 C 的 dll 中有一個簡單的函數(shù),它返回指向動態(tài)生成的字符串的指針.
                  它工作正常,但是因為我為字符串手動分配了內存,所以我應該在使用后釋放它.

                  I have a simple function in C-like dll which returns a pointer to the dynamically generated string.
                  It is working fine, but, because i manually allocated memory for the string, i should free it after use.

                  我有這樣的事情:

                  extern "C" char* DLL_EXPORT func(const char* str1, const char* str2)
                  {
                      return getSomeString(str1, str2);
                  }
                  
                  // Goal is to call this function correctly from Python.    
                  extern "C" void DLL_EXPORT freeMem(void *mem)
                      {
                          if(mem!=NULL)
                              delete mem;
                      }
                  

                  但我不知道,如何將接收到的指針傳回以在 Python 中刪除?

                  But i don't have any idea, how can i pass received pointer back for deletion in Python?

                  推薦答案

                  你在正確的軌道上.

                  // TestDLL.cpp
                  #include <string.h> // strcpy
                  
                  extern "C" __declspec(dllexport) char* stringdup(const char* str) {
                      char* p = new char[strlen(str)+1];
                      strcpy(p,str);
                      return p;
                  }
                  
                  // if you have no good reason to use void*, use the type
                  // you've allocated. while it usually works for built-in
                  // types, it wouldn't work for classes (it wouldn't call
                  // the destructor)
                  extern "C" __declspec(dllexport) void stringfree(char* ptr) {
                      // you don't need to check for 0 before you delete it,
                      // but if you allocate with new[], free with delete[] !
                      delete [] ptr; 
                  }
                  

                  在python中:

                  # Test.py
                  import ctypes
                  
                  lib = ctypes.cdll.TestDLL
                  
                  # this creates a c-style char pointer, initialized with a string whose
                  # memory is managed by PYTHON! do not attempt to free it through the DLL!
                  cstr = ctypes.c_char_p("hello ctypes")
                  
                  # call the dll function that returns a char pointer 
                  # whose memory is managed by the DLL.
                  p = lib.stringdup(cstr)
                  
                  # p is just an integer containing the memory address of the 
                  # char array. therefore, this just prints the address:
                  print p
                  
                  # this prints the actual string
                  print ctypes.c_char_p(p).value
                  
                  # free the memory through the DLL
                  lib.stringfree(p)
                  

                  這篇關于如何在ctypes中傳回指針?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How to bind a function to an Action from Qt menubar?(如何將函數(shù)綁定到 Qt 菜單欄中的操作?)
                  PyQt progress jumps to 100% after it starts(PyQt 啟動后進度躍升至 100%)
                  How to set yaxis tick label in a fixed position so that when i scroll left or right the yaxis tick label should be visible?(如何將 yaxis 刻度標簽設置在固定位置,以便當我向左或向右滾動時,yaxis 刻度標簽應該可見
                  `QImage` constructor has unknown keyword `data`(`QImage` 構造函數(shù)有未知關鍵字 `data`)
                  Change x-axis ticks to custom strings(將 x 軸刻度更改為自定義字符串)
                  How to show progress bar while saving file to excel in python?(如何在python中將文件保存為excel時顯示進度條?)
                    <tbody id='wO2io'></tbody>

                    <small id='wO2io'></small><noframes id='wO2io'>

                    <tfoot id='wO2io'></tfoot>

                        <bdo id='wO2io'></bdo><ul id='wO2io'></ul>
                        • <legend id='wO2io'><style id='wO2io'><dir id='wO2io'><q id='wO2io'></q></dir></style></legend>
                          1. <i id='wO2io'><tr id='wO2io'><dt id='wO2io'><q id='wO2io'><span id='wO2io'><b id='wO2io'><form id='wO2io'><ins id='wO2io'></ins><ul id='wO2io'></ul><sub id='wO2io'></sub></form><legend id='wO2io'></legend><bdo id='wO2io'><pre id='wO2io'><center id='wO2io'></center></pre></bdo></b><th id='wO2io'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='wO2io'><tfoot id='wO2io'></tfoot><dl id='wO2io'><fieldset id='wO2io'></fieldset></dl></div>

                            主站蜘蛛池模板: 日本不卡一区 | 日韩在线精品视频 | 日本人和亚洲人zjzjhd | 日韩欧美不卡 | 国产精品亚洲一区 | 国产一区二区精品在线 | 精品久久99 | 日韩欧美一区二区三区免费观看 | 黄色毛片视频 | 一级a爱片久久毛片 | 精品国产乱码久久久久久蜜臀 | 国产精品久久久久一区二区三区 | 精品伊人久久 | 国产91在线 | 中日 | 国产精品99久久久久久宅男 | 日本黄色免费大片 | 午夜99| 国产精品久久久久久久久 | 91一区二区在线观看 | 中文字幕第7页 | 国产美女在线观看 | 亚洲欧美日韩在线 | 国产一区二区三区色淫影院 | 91久久 | 亚洲精品视频免费 | 免费欧美视频 | 一区二区三区欧美大片 | 九九热免费看 | 日韩毛片 | 中文字幕人成乱码在线观看 | 人人九九精 | www日| 亚洲国产精品视频一区 | 久久久av | 碰碰视频| 午夜影院在线观看免费 | 中文字幕日韩欧美一区二区三区 | 成人国产精品免费观看 | 爱爱免费视频 | 日本精品一区二区三区在线观看视频 | 久久综合九九 |