pipje2001 1 Posted May 4, 2019 Is it possible to import a pyd file? i tried to import the file testC.pyd with this as code: (not actually a usefull code but just for testing) #include <Python.h> static PyObject *testCError; static PyObject* testC_say_hello(PyObject* self, PyObject *args){ const char* msg; int sts=0; if(!PyArg_ParseTuple(args, "s", &msg)){ return NULL; } if(strcmp(msg, "this_is_an_error") == 0){ PyErr_SetString(testCError, "This is a test exception"); return NULL; }else{ printf("This is C world\nYour message is: %s\n", msg); sts=21; } return Py_BuildValue("i", sts); } static PyMethodDef testC_methods[] = { {"say_hello", testC_say_hello, METH_VARARGS, "description"}, {NULL, NULL, 0, NULL} }; PyMODINIT_FUNC inittestC(void){ PyObject *m; m = Py_InitModule("testC", testC_methods); if(m == NULL) return; testCError = PyErr_NewException("testC.error", NULL, NULL); Py_INCREF(testCError); PyModule_AddObject(m, "error", testCError); } and i want to import this from mod_test.pyc: import testC status = testC.say_hello("morning") both files are in C:\Games\World_of_Tanks_EU\res_mods\1.5.0.0\scripts\client\gui\mods but when i try this it just gives me this error: ERROR: [EXCEPTION] (scripts/client/gui/mods/__init__.py, 74): Traceback (most recent call last): File "scripts/client/gui/mods/__init__.py", line 67, in _findValidMODs File "scripts/common/Lib/importlib/__init__.py", line 37, in import_module File "mod_test", line 2, in <module> ImportError: No module named testC i feel like i am doing something very simple wrong or it isn't even possible in world of tanks. Does anyone has an idea? Quote Share this post Link to post Short link Share on other sites
Mixaill 1,737 #457862 Posted May 4, 2019 (edited) 0) Please do not use .pyd in WoT if you can to implement your mod in pure python. 1) AFAIK, you need to load .pyd via imp.load_dynamic() function 2) you need to built it against XFW.Native ( https://bitbucket.org/XVM/xfw.native/ ) Edited May 4, 2019 by Mixaill Quote Share this post Link to post Short link Share on other sites
pipje2001 1 #457865 Posted May 4, 2019 2 minutes ago, Mixaill said: 0) Please do not use .pyd in WoT if you can to implement your mod in pure python. I wouldn't ask it if was possible in pure python :) , but why should I use it? Quote Share this post Link to post Short link Share on other sites
Mixaill 1,737 #457867 Posted May 4, 2019 So, because WoT is statically linked with libpython, you do not have the option of using .pyd modules by default. That's why: a) you need to use pythonXY.dll wrapper for WoT (XFW.Native approach) b) or you can find addresses for the Python/C api functions yourself ( memhelper approach koreanrandom.com/forum/topic/27531-/ ) Quote Share this post Link to post Short link Share on other sites
pipje2001 1 #457868 Posted May 4, 2019 I see, I want to be as independent from other stuff as possible so I will try the second option I think, also why is it bad to use pyd? Quote Share this post Link to post Short link Share on other sites
Mixaill 1,737 #457870 Posted May 4, 2019 Только что, pipje2001 сказал: I see, I want to be as independent from other stuff as possible so I will try the second option I think, also why is it bad to use pyd? * your mod may be broken with a Worldoftanks.exe update (or it may be broken at each update, depending on the api search implementation) * your mod may cause the game to crash * your mod may be broken by user's AV software * your mod can be broken forever when WG integrates client anticheat * possible problems with MacOS / Linux (incompatibility with CrossOver/Wine wrappers) Quote Share this post Link to post Short link Share on other sites
pipje2001 1 #457871 Posted May 4, 2019 I see why it's bad to use CD but what I am trying is just not possible in python so I don't have a choice :/ Is xfm only needed to build the file or also when using the mod? Quote Share this post Link to post Short link Share on other sites
Mixaill 1,737 #457926 Posted May 5, 2019 13 часов назад, pipje2001 сказал: Is xfm only needed to build the file or also when using the mod? You need to use headers from XFW.Native and wotmod which containts python27 wrapper dll. devel package: com.modxvm.xfw.native_1.4.3.00085-devel.zip redistributable wotmod for end users: com.modxvm.xfw.native_1.4.3.00085.wotmod 13 часов назад, pipje2001 сказал: I see why it's bad to use CD but what I am trying is just not possible in python so I don't have a choice :/ You can also start executable via subprocess module and communicate with it via standard streams or named pipes. Quote Share this post Link to post Short link Share on other sites
pipje2001 1 #457947 Posted May 5, 2019 @MixaillThanks for the response, a wotmod is not such a big deal so i guess using xfm.native is fine. But is there some explanation about how to use it? i am not that experienced and i can't find an explanation anywhere Quote Share this post Link to post Short link Share on other sites