1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| int CPluginManager::GetInfo(int count, CString& result)
{
PyObject *pName, *pModule, *pDict, *pFunc, *pValue, *pInfo, *pResult;
// On modifie le PATH de l'interpréteur Python pour qu'il aille chercher les plugins où il faut
PySys_SetPath("..\\Plugin;..\\lib;..\\lib\\site-packages");
pName = PyString_FromString((CStringA)vPluginAdr[count]);
// Error checking of pName left out
pModule = PyImport_Import(pName);
Py_XDECREF(pName);
if (pModule != NULL) {
// On accède au dictionnaire du module
pDict = PyModule_GetDict(pModule);
pInfo = Py_BuildValue("[s]", "");
// On ajoute un attribut à notre dictionnaire
PyDict_SetItemString(pDict, "info", pInfo);
pFunc = PyObject_GetAttrString(pModule, "GetInfo");
// pFunc is a new reference
if (pFunc && PyCallable_Check(pFunc)) {
pValue = PyObject_CallObject(pFunc, NULL);
if (pValue != NULL) {
// On accède à une propriété du dictionnaire
pResult = PyDict_GetItemString(pDict, "info");
result = PyString_AsString(PyList_GET_ITEM(pResult,0));
Py_DECREF(pValue);
Py_DECREF(pResult);
}
else {
Py_DECREF(pFunc);
Py_DECREF(pModule);
return 1;
}
}
PyErr_Clear();
Py_XDECREF(pFunc);
Py_XDECREF(pDict);
Py_XDECREF(pInfo);
Py_XDECREF(pModule);
}
return 0;
} |
Partager