How to convert python strings to wchar_t* in Cython

Hi all,
I want to convert a python string to wchar_t* aka LPCWSTR in Cython. I see this code sample in Cython docs.

cdef extern from "Windows.h":

    ctypedef Py_UNICODE WCHAR
    ctypedef const WCHAR* LPCWSTR
    ctypedef void* HWND

    int MessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, int uType)

title = u"Windows Interop Demo - Python %d.%d.%d" % sys.version_info[:3]
MessageBoxW(NULL, u"Hello Cython \u263a", title, 0)

It uses string literals. But how could I use python strings that came as a function parameter. For example see this function.

def createForm(title, w, h, x, y):  # How do I convert the title here ?
    cdef HWND hw = CreateWindowExW(....)

This is the one way which worked for me now.

def createForm(title, w, h, x, y):  
    cdef LPCWSTR wTitle = PyUnicode_AsWideCharString(title, NULL)
    cdef HWND hw = CreateWindowExW(....)
    PyMem_Free(wTitle)