Getting the object from a memory address using ctype python









up vote
0
down vote

favorite












Basically I have a ctype structure like below:




class A(Structure):
fields = [('x', c_uint),
('y', c_uint),
('z', c_char_p),
('a', c_wchar_p),
('b', c_uint),
('c', c_uint),
('d', c_uint),
('e', c_uint),
('f', c_uint),
('g', c_uint)]
pack = 1




Now i have a below function where i am instantiating the class and setting the values



def func( self,x,y):



 ins = A()
ins.x = 3
ins.y = 4


now i need to pass the pointer to the memory location of the structure
ptr = pointer(ins) also tried addressof
passing the pointer to a function(memory address basically)
func2(param1,ptr)
now i want to check the all values like x,y,z etc from the pointer if there are any changes
ptr.contents()-->not working for me




so if anyone know how to get the values back , that would be great help.
i know there are may be any methods that i can use, also tried. but everything fails











share|improve this question



























    up vote
    0
    down vote

    favorite












    Basically I have a ctype structure like below:




    class A(Structure):
    fields = [('x', c_uint),
    ('y', c_uint),
    ('z', c_char_p),
    ('a', c_wchar_p),
    ('b', c_uint),
    ('c', c_uint),
    ('d', c_uint),
    ('e', c_uint),
    ('f', c_uint),
    ('g', c_uint)]
    pack = 1




    Now i have a below function where i am instantiating the class and setting the values



    def func( self,x,y):



     ins = A()
    ins.x = 3
    ins.y = 4


    now i need to pass the pointer to the memory location of the structure
    ptr = pointer(ins) also tried addressof
    passing the pointer to a function(memory address basically)
    func2(param1,ptr)
    now i want to check the all values like x,y,z etc from the pointer if there are any changes
    ptr.contents()-->not working for me




    so if anyone know how to get the values back , that would be great help.
    i know there are may be any methods that i can use, also tried. but everything fails











    share|improve this question

























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      Basically I have a ctype structure like below:




      class A(Structure):
      fields = [('x', c_uint),
      ('y', c_uint),
      ('z', c_char_p),
      ('a', c_wchar_p),
      ('b', c_uint),
      ('c', c_uint),
      ('d', c_uint),
      ('e', c_uint),
      ('f', c_uint),
      ('g', c_uint)]
      pack = 1




      Now i have a below function where i am instantiating the class and setting the values



      def func( self,x,y):



       ins = A()
      ins.x = 3
      ins.y = 4


      now i need to pass the pointer to the memory location of the structure
      ptr = pointer(ins) also tried addressof
      passing the pointer to a function(memory address basically)
      func2(param1,ptr)
      now i want to check the all values like x,y,z etc from the pointer if there are any changes
      ptr.contents()-->not working for me




      so if anyone know how to get the values back , that would be great help.
      i know there are may be any methods that i can use, also tried. but everything fails











      share|improve this question















      Basically I have a ctype structure like below:




      class A(Structure):
      fields = [('x', c_uint),
      ('y', c_uint),
      ('z', c_char_p),
      ('a', c_wchar_p),
      ('b', c_uint),
      ('c', c_uint),
      ('d', c_uint),
      ('e', c_uint),
      ('f', c_uint),
      ('g', c_uint)]
      pack = 1




      Now i have a below function where i am instantiating the class and setting the values



      def func( self,x,y):



       ins = A()
      ins.x = 3
      ins.y = 4


      now i need to pass the pointer to the memory location of the structure
      ptr = pointer(ins) also tried addressof
      passing the pointer to a function(memory address basically)
      func2(param1,ptr)
      now i want to check the all values like x,y,z etc from the pointer if there are any changes
      ptr.contents()-->not working for me




      so if anyone know how to get the values back , that would be great help.
      i know there are may be any methods that i can use, also tried. but everything fails








      python pointers memory ctype






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 11 at 6:00

























      asked Nov 10 at 15:28









      Bikash Dash

      14




      14



























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240427%2fgetting-the-object-from-a-memory-address-using-ctype-python%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240427%2fgetting-the-object-from-a-memory-address-using-ctype-python%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          How to read a connectionString WITH PROVIDER in .NET Core?

          Node.js Script on GitHub Pages or Amazon S3

          Museum of Modern and Contemporary Art of Trento and Rovereto