ich beschaeftige mich gerade mit dem Einbetten eines Python-Skriptes in eine DLL. Selbige hat folgenden Code (der nicht sehr viel macht, weil ich das meiste zum Debuggen auskommentiert habe):
Code: Alles auswählen
#include "DLLTest.h"
using namespace std;
extern "C"
{
DECLDIR int getDataPy(CStr LStr, dataAnalogHdl inA, long samplerate) {
PyObject *pName, *pModule, *pFunc;
PyObject *pArgs, *pValue;
char *patternString = "pattern(10,100,1,1,2,3,4,5,6,7,8)\n";
Py_Initialize();
_import_array();
pName = PyString_FromString("pattern");
pModule = PyImport_Import(pName);
Py_DECREF(pName);
if (pModule != NULL) {
pFunc = PyObject_GetAttrString(pModule, "getData");
pArgs = PyTuple_New(2);
PyTuple_SetItem(pArgs, 0, PyString_FromString(patternString));
PyTuple_SetItem(pArgs, 1, PyInt_FromLong(samplerate));
if (pFunc && PyCallable_Check(pFunc)) {
pValue = PyObject_CallObject(pFunc, pArgs);
Py_XDECREF(pArgs);
Py_XDECREF(pFunc);
Py_XDECREF(pModule);
}
else {
Py_XDECREF(pArgs);
Py_XDECREF(pFunc);
Py_XDECREF(pModule);
return 2;
}
}
else {
return 1;
}
Py_Finalize();
return 0;
}
Code: Alles auswählen
def getData(inS, samplerate):
f = open("error.log", 'a')
f.write(str(inS))
f.close()
return 0
vG, U.