Это Dll . конечно так делать нельзя, запускать поток при инициализации dll. Это черевато крашем, но в данном случае это работает.Счетчик потока у таргета увеличивается, файл с отчетом создается.
#include <thread>
#include "C:\Python34\include\python.h"
DWORD WINAPI thread1(CONST LPVOID lpParam)
{
Py_Initialize();
PyRun_SimpleString("import sys");
PyRun_SimpleString("handle = open('c:\\output.txt',mode='w',encoding='utf-8')");
PyRun_SimpleString("z=15");
PyRun_SimpleString("t=dir()");
PyRun_SimpleString("vers=(sys.version)");
PyRun_SimpleString("handle.write('System version = ' + vers + '\\n')");
PyRun_SimpleString("handle.write(' '.join(t))");
PyRun_SimpleString("handle.close()");
return 0;
}
{
HANDLE th;
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
{
th=CreateThread(NULL, 0, &thread1,0, 0, NULL);
break;
}
}
а вот содержимое файла отчета .
System version = 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (Intel)]
__builtins__ __doc__ __loader__ __name__ __package__ __spec__ handle sys z
Как видно, интерпретатор 3.4 , а таргет работает с python27.dll
Без Py_Initialize(); моментальный краш
doza_and
Только я хоть убей не понимаю зачем? Вы хотите получить доступ к интерпретатору используемому вашей игрой. Вместо этого вы запускаете второй интерпретатор никак не связанный с первым.
Наверное надо как-то получить объект интерпретатора таргета.
Есть какие то хитрости, попасть в его пространство ?
____________
Есть небольшая инструкция …
1. Read in the plain python code and store it in memory
2. Get the process ID for the client process
3. Attach to the process object
4. Allocate a remote thread
5. Populate the remote thread with code
6. Allocate and populate parameters
7. Start the remote thread
Execution is now taking place in the client process
8. Get a handle for the python DLL
9. Get a handle for
(a) PyRun_SimpleString – Runs a python string in the global interpreter context
(b) PyGILState_Ensure – Acquires the python Global Interpreter
Lock (GIL)
(c) PyGILState_Release – Releases the Global Interpreter Lock
10. Acquire the GIL
11. Execute the python code
12. Release the GIL
Может вам покажется это значимым