C code:
#include "Python.h"
#include <windows.h>
__declspec(dllexport) PyObject* getTheString()
{
auto p = Py_BuildValue("s","hello");
char * s = PyString_AsString(p);
MessageBoxA(NULL,s,"s",0);
return p;
}
Python code:
import ctypes
import sys
sys.path.append('./')
dll = ctypes.CDLL('pythonCall_test.dll')
print type(dll.getTheString())
Result:
<type 'int'>
How can I get pytype(str)'hello' from C code? Or is there any Pythonic way to translate this pytype(int) to pytype(str)?
It looks like no matter what I change,the returned Pyobject* is a pytype(int) no else