Hi can you help me im new in python; i tried to call python functions inside c++ and i copied your sample source code and put it in my created function. I comment out the Py_Initialize() and Py_Finalize() because they are called in different part of the program.
I put a break point in the function but the problem is when the game reads the line: func = PyDict_GetItemString(mdict, "PnlPackSel"); it returns NULL.
Any help will be appreciated
C++ Source code:
int GC_PythonCalls()
{
double answer = 0;
PyObject *modname, *mod, *mdict, *func, *stringarg, *args, *rslt;
// Py_Initialize();
modname = PyString_FromString("Menu");
mod = PyImport_Import(modname);
if (mod)
{
mdict = PyModule_GetDict(mod);
func = PyDict_GetItemString(mdict, "PnlPackSel"); /* borrowed reference */
if (func)
{
if (PyCallable_Check(func))
{
rslt = PyObject_CallObject(func, NULL);
if (rslt)
{
//answer = PyFloat_AsDouble(rslt);
Py_XDECREF(rslt);
OutputDebugString("PY CALL SUCCESS \n");
}
Py_XDECREF(stringarg);
Py_XDECREF(args);
}
}
Py_XDECREF(mod);
}
Py_XDECREF(modname);
//Py_Finalize();
return 0;
}
Python Code
def PnlPackSel(self):
App.CtrlMouseSet(100,100)
Pnl = self.PCtrlTopGet();
#bring
self.PCtrlAdd(
self.__class__.AddLvl,
(self, Pnl.ulPackId, False),
True,
);
Thanks in advance