Python??C???????
???????????? ???????[ 2016/5/10 14:03:42 ] ????????.NET ???????????
???????python????Ч????????????????????????????????????????Ч???????????????????????????c??c++??????????c??c++??????python??????????????????????python???Щ???????????????????????????????????Plugin??????????????????????????????б???????????????????????c??????python????????python??c??????????????c??python?????????????????????????????
???????????
?????????c??????python?????????????????????python???????????????python?????????python???????libs?е?python27.lib???????????????????????????п??????google?????????c???????python???Щ??????????????????????python??????μ?include?????????include???С??????????????????Щ???????????????????????????????????
???????python?????
??????c?????python????????????????????include Python.h???????????????????????????python?????????????
????1 Py_SetPythonHome("D:Python27");
????2 Py_Initialize();
????Py_SetPythonHome??????????????python???·???????python???·????Py_Initialize????????????????python????????????????python??????????c?????
????????python???
??????python??????????????????????python??????c?е??y??????е?????????漸?????裺
????1?????PyImport_ImportModule????????飻
????2?????PyObject_GetAttrString??????????????????
????3?????Py_VaBuildValue????????????
????4?????PyObject_CallObject?????????????
????5?????PyArg_Parse????????????????
?????????????????????????е????????????????????д????????????????5?????裬??????????£?
1 int PyModuleRunFunction(const char *module?? const char *function??
2 const char *result_format?? void *result?? const char *args_format?? ...)
3 {
4
5 PyObject *pmodule?? *pfunction?? *args?? *presult;
6
7 pmodule = PyImport_ImportModule(const_cast<char *>(module));
8 if (!pmodule)
9 {
10 PyObject *type = PyErr_Occurred();
11 if (type == PyExc_NameError)
12 {
13 PyErr_Clear();
14 return 0;
15 }
16
17 PyError("PyModuleRunFunction");
18 return -1;
19 }
20
21 pfunction = PyObject_GetAttrString(pmodule?? const_cast<char *>(function));
22 Py_DECREF(pmodule);
23 if (!pfunction)
24 {
25 PyObject *type = PyErr_Occurred();
26 if (type == PyExc_AttributeError)
27 {
28 PyErr_Clear();
29 return 0;
30 }
31
32 PyError("PyModuleRunFunction");
33 return -2;
34 }
35
36 if (pfunction == Py_None)
37 {
38 return 0;
39 }
40
41 va_list args_list;
42 va_start(args_list?? args_format);
43 args = Py_VaBuildValue(const_cast<char *>(args_format)?? args_list);
44 va_end(args_list);
45
46 if (!args)
47 {
48 Py_DECREF(pfunction);
49 return -3;
50 }
51
52 presult = PyObject_CallObject(pfunction?? args);
53 if (presult == 0)
54 {
55 PyError("PyModuleRunFunction");
56 Py_XDECREF(pfunction);
57 Py_XDECREF(args);
58 return -1;
59 }
60
61 Py_XDECREF(pfunction);
62 Py_XDECREF(args);
63
64 return ConvertResult(presult?? result_format?? result);
65 }
????????????????python????????????ú??????????????????python????е??????????????£?
????1 PyModuleRunFunction("hello"?? "test"?? ""?? 0?? "()");
???????????????????c?е???python???????????????????????python???????c?е??????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11