Hi,
     I wish to call a function in c++ dll which returns a unicode array from 
python.
 
 
 
extern "c"
{
__declspec(dllexport) int test(wchar_t** ppText)
{
      *ppText = new wchar_t[30];
       wcscpy(*ppText, L"this is a test");
       return 0;
}
 
 
__declspec(dllexport) int FreeString(wchar_t** ppText)
{
      delete [] *ppText;
       return 0;
}
 
}
 
 
 
In python I'm doing this
 
import ctypes
dll = ctypes.cdll.LoadLibrary(r"x")
func = dll.test
func.argtypes = [ ctypes.POINTER(ctypes.c_wchar_p)]
 
funcDel = dll.FreeString
funcDel.argtypes = [ctypes.POINTER(ctypes.c_wchar_p)]
 
a = ctypes.c_wchar_p('')
z = ctypes.pointer(a)
 
n= func(z)
 
print a  /* displays  "this is a test" */
 
/* is this correct way to return charater array */
/* will memory allocated in c++ function be freed by python */
/* or should I call */
 
n = funcDel(z)
 
 
thanks,
Nitin.
 
 
                                          
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to