So I'm trying to run a python function in my windows app but I'm having some trouble with this line here:
pFunc = PyObject_GetAttrString(pModule, (char*)"download");
this is the full code:
if (SendMessage(download, BM_GETSTATE, 0, 0)) {
Py_Initialize();
// CODE TO RUN PYTHON FUNCTION
PyObject* output = PyUnicode_FromString("C:\\Users\\User\\Desktop");
PyObject* ytlink = PyUnicode_FromString("https://www.youtube.com/watch?v=G9cyeZfLeQc&ab_channel=FIRSTRoboticsCompetition");
PyObject* pName, * pModule, * pFunc, * pArgs, * pValue;
pName = PyUnicode_FromString((char*)"Downloader.py");
pModule = PyImport_Import(pName);
pFunc = PyObject_GetAttrString(pModule, (char*)"download");
pArgs = PyTuple_Pack(2, ytlink, output);
pValue = PyObject_CallObject(pFunc, pArgs);
Py_Finalize();
}
I was following this tutorial: https://medium.datadriveninvestor.com/how-to-quickly-embed-python-in-your-c-application-23c19694813
I'm really new to running python in c++ so I'm not sure whether or not I'm missing something obvious or whether there is something else going on.
this was the exact error:
Unhandled exception at 0x00007FFF8F278B13 (python310_d.dll) in YTDownloader.exe: 0xC0000005: Access violation reading location 0x0000000000000008.