Recreating a char array from a pointer

buffinator buffinator at mymail.com
Sat Feb 24 11:10:55 EST 2007


I have an application that has to send a string as a pointer to memory, 
and then another one that has to retriece it and fetch the string. 
Converting the string to an array and sending the pointer was easy

import array
a=array.array("c","mytextgoeshere")
my_pointer = a.buffer_info()[0]


But then I tried to get the data back... and I just can't find out how. 
I ended up writing a C module for this that works fine in linux, but 
this application is meant for windows and I just can't get C-modules to 
compiler there correctly since I suck at windows.

The relevant code from the module is

static PyObject *
pointrtostr_casttostr(PyObject *self, PyObject *args)
{
     char *mystr;
     long int p;

     if (!PyArg_ParseTuple(args, "l", &p))
       return NULL;

     mystr = (char*)p;
     return Py_BuildValue("s", mystr);
}

My question is... can I do the above code in python without involving C 
since it is quite a big hassle to have to go through the module building 
in windows? :/

/buffis



More information about the Python-list mailing list