Jun-24-2020, 04:39 PM
Hello everyone,
I'm wrapping some C++ in Python using ctypes.
I have the following problem:
When I'm trying to open/read a txt file by calling a void method in .dll file from Python (no arguments passed from or to python), program fails. Terminal either "hangs" like it's waiting for input or it just passes through without carrying out the open file instructions.
Here is the bare bones example of problematic code
The C++ example.cpp file: (I used python code tags cause there aren't any others to use for code other than Python)
The python ctypes wrapper:
I tried this with Python 2 and 3 (64bit) on Windows. In both cases issue is thesame.
I belive this has something to do with C++ vs Python streams but I don't know what and I don't know how to get around that.
My question is:
How to open/read text file by calling a funcion in .dll from Python wrapper ?
Any help appreciated.
I'm wrapping some C++ in Python using ctypes.
I have the following problem:
When I'm trying to open/read a txt file by calling a void method in .dll file from Python (no arguments passed from or to python), program fails. Terminal either "hangs" like it's waiting for input or it just passes through without carrying out the open file instructions.
Here is the bare bones example of problematic code
The C++ example.cpp file: (I used python code tags cause there aren't any others to use for code other than Python)
#include <sdtio.h> extern "C" { __declspec(dllexport) void test(){ File* f_name; f_name = fopen("file.txt", "r"); //the "file.txt is in directory" //... doesn't goes past this^ line } }C++ code is compiled by cygwin64 to example.dll
The python ctypes wrapper:
import ctypes lib = ctypes.CDLL("D:\Code Blocks\C_cwiczenia\stack_over\example.dll") void_acc = lib.test void_acc.restype = None void_acc() print "program ended !" # this is just so I can see if program executedAs mentioned in C++ code snippet, program doesn't get passed the fopen() line so no "program ended !" shows in Python console.
I tried this with Python 2 and 3 (64bit) on Windows. In both cases issue is thesame.
I belive this has something to do with C++ vs Python streams but I don't know what and I don't know how to get around that.
My question is:
How to open/read text file by calling a funcion in .dll from Python wrapper ?
Any help appreciated.