C++ invocation via Python Ctypes

Asked 2 years ago, Updated 2 years ago, 18 views

Hello, everyone You want to import the main() function of the C++ file into ctypes and express it as a Tkinter module with the name c_main(). I want to put the contents that appear in the cmd window into the scrolled text box made of Tkinter, but only return is returned (C++ file main function returns 0;) The contents of the cmd window don't go in. I want to put the contents expressed in printf in the cmd window, is there any way?

Add)) By any chance


extern "C" __declspec(dllexport)

 int file(int a, int b)
{
    return a + b
   }

Is there a way to give the main function an argument or variable as an input like a and b?

`

python ctypes

2022-09-22 18:07

1 Answers

https://stackoverflow.com/questions/665566/redirect-command-line-results-to-a-tkinter-gui

The simplest way is to run an external executable file through the subprocess, receive the output from the pipe, and spray it on the tk window.

However, since the output contains Korean, you should be careful about encoding. First of all, I recommend you to take out Korean from the output, change it to English, and test it, and think about encoding later.

If you want to stick to the way you create dlls and run functions, you'll have to change the function in a way that returns what's currently being output. This may be simpler for character coding.


2022-09-22 18:07

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.