<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>
Hi,<BR>
I wish to call a function in c++ dll which returns a unicode array from python.<BR>
<BR>
<BR>
<BR>
extern "c"<BR>
{<BR>
__declspec(dllexport) int test(wchar_t** ppText)<BR>
{<BR>
*ppText = new wchar_t[30];<BR>
wcscpy(*ppText, L"this is a test");<BR>
return 0;<BR>
}<BR>
<BR>
<BR>
__declspec(dllexport) int FreeString(wchar_t** ppText)<BR>
{<BR>
delete [] *ppText;<BR>
return 0;<BR>
}<BR>
<BR>
}<BR>
<BR>
<BR>
<BR>
In python I'm doing this<BR>
<BR>
import ctypes<BR>
dll = ctypes.cdll.LoadLibrary(r"x")<BR>
func = dll.test<BR>
func.argtypes = [ ctypes.POINTER(ctypes.c_wchar_p)]<BR>
<BR>
funcDel = dll.FreeString<BR>
funcDel.argtypes = [ctypes.POINTER(ctypes.c_wchar_p)]<BR>
<BR>
a = ctypes.c_wchar_p('')<BR>
z = ctypes.pointer(a)<BR>
<BR>
n= func(z)<BR>
<BR>
print a /* displays "this is a test" */<BR>
<BR>
/* is this correct way to return charater array */<BR>
/* will memory allocated in c++ function be freed by python */<BR>
/* or should I call */<BR>
<BR>
n = funcDel(z)<BR>
<BR>
<BR>
thanks,<BR>
Nitin.<BR>
<BR>
<BR>
<BR> </div></body>
</html>