I have written a C# application, which communicates with C++ dll to process some things. The C++ .dll actually has some commands system(TestApplication1) , system(TestApplication2) etc.
While I run my C# application, and send a call to C++ function, these cmd windows open and close to do their work. Since my C# application is meant for a GUI front-end, I want to supress these windows from loading up.
I remmeber in C# when we load some process, we have the option to pass ProcessWindowStyle=Hidden in the arguments, but I am not sure how it can be done in this scenario.
I wouldn't prefer to make my application full screen, make it TopMost, and Maximized. Any suggestions?
Related
I want to make a GUI Windows application that can run console applications. When this happens, the console window should not be shown. Instead its content should be shown in a visual component (memo/richedit). This component should show exactly the same content which would appear in the console window, even the color of the text and its background should be displayed. So this visual component should work exactly as a console window. I know that the standard output can be captured but many console applications do not use it. Is it possible to capture the output of a console application this way? Are there Windows API calls that can handle this?
I use Delphi XE2 but C# code would also be helpful.
You have to run the console mode program with stdout redirection to a pipe that your Delphi program will create. Your Delphi program can read the pipe to get the console mode program output and do whatever it needs to. By the way, this works not only with Delphi but also with any language able to create pipe and run program with I/O redirection.
If you need Delphi code to do that, have a look at this reference.
There is a ready-to-run component on GitHub: DosCommand
The Demo shows two ways how to do what you describe.
I am not sure if it works for older versions like XE2, but at least you can give it a try.
Traditionally you would call CreateProcess with stdin/stdout set to pipes you created. This should work for most programs but not for anything that uses a ncurses style "GUI" and you also lose the color information. An example can be found on MSDN.
Windows 10 (1809?) added support for pseudoconsoles. This is used by the new Terminal application and is your best bet for full console compatibility.
The last alternative is to inject into the child process and hook WriteFile, ReadFile and all the console functions but this is ugly and error-prone.
I need to run an unmanaged C++ application, this application must be connected to a library in C# (dll which when loading must show a form with a button) and wait for form close event to terminate.
While the form is loaded, at the moment of pressing the button the click event should be executed, which should execute a function that can send a number of return to the console application in C ++ and this application will show the resulting number in the output of the console.
What I need is to solve point 5. shown below, I read a lot of documents but almost all refer to the interoperation between a C++ dll and a C# application and not the reverse (Return an integer value from C# dll to a C++ console application) is what is needed here.
The execution must be dynamic, that is, while the form is displayed, a communication should be established from a function of the C# library and a function of the parent C++ console application.
All the examples that I have been able to find do almost the same, load the libraries, establish the communication and, from the C++ console application they call a function of the C# library and show the resulting return value and the application ends, but no example shows how to load the C# library, show the form, press a button, and send a integer number as a result to the C++ parent console application and show the result in the output of the console.
If you have any idea how to implement the Callback, I would be very grateful.
What I have tried:
What has been achieved is:
Load C++ console application (unmanaged), achieved
Load a C# library from the C++ console application, achieved
Import and communicate with some functions exported from the C# library, achieved
When loading the C# library, from this library a form with an button is shown, achieved
While the form is displayed, press the button and execute a function in C# that returns an integer to the C++ console application and print the result in the output of the console from the C++ console application, pending
One proposition: When your app C# want to send a value, it writes it in a file in folder C:\Temps\token.txt.
Then, if your application C++ detects a file named token.txt (by a loop for each 10s for example) in C:\Temps, it reads it and gets the value
There are 2 solution not related to network or interprocess communications at least
call unmanaged callback or delegate from managed code (see "How to: Marshal Callbacks and Delegates By Using C++ Interop")
use an event object to signal pressed button and a named shared memory to pass a value back
Please note that implementing complex things to doing simple ones is the characteristic of not well designed application.
I've made a Launcher for my game, and the launcher auto-download and patches the game.
But, how can I check if the game has been launched by the Launcher? Is there a way to do it without using Command Line Arguments?
If your launcher is .net application, you can start your application not from command line, but by calling Main() function (from exported class).
If your launcher is not .net application and your application works on Windows only, then you can try to find launcher's window (using FindWindow function) from main application, send message using SendMessage WinApi function, and check result.
These articles might be usefull:
Importing .net classes
Finding windows
Sending messages
Importing dll functions
I have a .Net windows C# application, fairly complete and working, that I have been asked to support calling it from another program like LabView. I have added the ability to parse command line arguments at startup so I can detect that it is supposed to behave like a console application and be provided with enough information to function.
What I would like to do is have the program print out to the console its results and have the calling program pipe it or just pull the data and use it.
The printing to the console works fine but when I start the program up, it tells the command prompt window that it is done (a new prompt immediately shows up and the command prompt is waiting for input). In the process it also closes the redirection that was part of the startup line. Is there anyway to keep it from telling the calling program that it has completed before it has actually finished?
The simple solution is to pass a file to save the data to but I would prefer not to have to do that. I could also do a separate version that is a console app, but that means supporting two separate programs.
Thanks
Instead of invoking the program directly, you can use cmd /c myapp.exe.
I have a C# Console app than runs a pre-build step (to get NuGet Packages).
When I am debugging this, I want to pass in a parameter and show the console. When I am not debugging it I don't want to see it. I don't even want it to flash up there for a second.
I have found ways to hide it, after it has shown. But I can't find a way to never make it show unless I am willing to change it from a console app to a Windows app. (Which I would do if I could then find a way to show the Console when needed.)
Build as a Windows application and show the console when you need it. To show the console when needed use P/Invoke to call AllocConsole (pinvoke.net has the declaration you need).
(Console sub-system processes always get a console, their parent process's if there was one, otherwise a new one. This is the way Windows works at a deep level.)
Use FreeConsole WINAPI function:
http://pinvoke.net/default.aspx/kernel32/FreeConsole.html
Another solution is to simply switch to a WinForms application as project type. No console will be allocated then (and you do not need to show a form).