I have created a program that extracts data from a racing game and sends it to a speed gauge cluster. I call it the transfer program.
I need a simple user-friendly User Interface to start the transfer program, set some variables and choose a COM Port. At the moment I'm trying to do it with a C++ Windows Forms Application in a CLR Project on Microsoft Visual Studio 2015. When I tried to do it directly (creating the UI in the same project as the transfer program) I just get too many errors that I have no idea where they come from or why they are there.
So I've decided maybe I could try creating some sort of launcher, i.e. a completely different program that is only the UI to start the transfer program and send a few user-set variables to it on startup as well as choose a COM Port to communicate on.
Any idea on how to start on this? How do I execute the transfer program from the Launcher? How do I send variables and data to it?
Thank you very much!
There are basically two ways to pass information to your transfer program.
For simple use cases, just pass the values along on the command line. If you're still using the CLR, this is done using System.Diagnostics.Process. A nice example can be found in this answer: https://stackoverflow.com/a/33633148/127826
Use a shared configuration file. So the user interface loads the values from the config and also saves the file before executing the transfer program. The transfer program then reads the same configuration file to get the values it needs.
The second approach is far more flexible and is what I would use.
Related
I want create a kernel driver program to monitor certain kernel events such as creating files, so that I receive a notification whenever a file is created, including the process ID of the process that created the file. I already created a program where I can see the files which are opened in the system, by creating an handler for IRP_MJ_CREATE.
I used this project as a reference.
There are several ways to do it, with the file system filter being the most complete. However for simple notifications, the easiest way to do it is through a minifilter.
You have several examples by microsoft:
https://github.com/microsoft/Windows-driver-samples/tree/master/filesys/miniFilter
Here is the reference: https://learn.microsoft.com/en-us/windows-hardware/drivers/ifs/ifs-reference
Do note however that you can do this without a driver, so unless you have a very good reason to do it in kernel space, you can do it from userspace. See FindFirstChangeNotification:
https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-findfirstchangenotificationa
Here is the deal : I have created a data transfer program that sends info to my Arduino over Serial Port. I have also created a simple "launcher" program with a basic UI for the user to Select the COM Port and launch the program. It is basically just a Windows Forms Application with a DropDown Combo Box for the COM Port and a "Launch" Button that starts the Transfer Program.
The Launcher and the Transfer Program are separate, so I need a way for the Transfer Program to get the information of the Serial Port the user chooses on the Launcher before starting the program.
I've looked into config files, shared txt files etc. but found nothing but overly-complicated programs.
Any help would be appreciated!
Thanks,
Frazic
There are some ways to do that.
1. Start your program with parameters using int main(int argc, char* argv[])
For more Information: How to parse command line parameters.
And you can run your tool with: system("C:\\Program Files (x86)\\MyProgram\\transfer.exe ParamCOM");
2. Put your transfer program in to a dll and call it from your GUI. With that solution you could transfer data in both directions while the transfer program is running. Walkthrough: Creating and Using a Dynamic Link Library (C++)
3. Write the COM information from your GUI in a config.txt file before you call the transfer program. Now your transfer program could read the information from the file.
4. Read memory from a different process using WinAPI. That is not a common way but it works. Searching for the right values is not that easy so I would prefer Point 1 - 3.
You can pass the data as commandline arguments.
You can pass the data in the environment.
You can pass the data in a file on disk.
You can pass the data through pipes or sockets between the two programs.
You can pass the data via shared memory.
And more ...
There are many options.
Suppose I'm running a small program on the server. for example, a random number generator and sending the result to a client every second. I know that my server is about to be turned off. Is there a way to clone the program to another server so that the client doesn't notice it?
ideally i would want to save the dynamic object of the small program, send it to another server and re-link it with another server using dynamic linking. If that is possible then the question is how to save/hibernate that small program.
another obvious solution is to serialize the all states of the project and send it to another server but that would involve changing the small program, which is not desirable.
I'm not even sure what keywords to search for.
(i would like to avoid system calls, if possible. if not then it's fine.)
update (1)
the defult platform is linux but i'm also interested in embedded systems and nacl
I am working on a windows sever program using c++, when the program started it stays for several days and output important logs to the default windows console.
now I want to add some control function to the console, like I cound enter something like query or stop, and the program ouput the variable number or stop accept requests. So there is the problem, I got two output stream(log and query response) and one input stream both mixed in one single console.
How do I seperate the three different stream in one single console? Maybe I cound write my own console to replace the default windows console?
I believe this is a very normal need and a lot of server application has implemented this but I could not find any source code...
I know I could use ncurses, but I think ncurses seems too low level for this. Any suggestion will be apprecitated.
This shouldn't be an unusual problem, but I cannot find anything about it at google or at other search machine.
So, I've made an application using C++ and QtCreator. I 've made a new mime type for application's project files.
My system (ubuntu 10.10), when I right click a file and I choose "Open With 'Default Application'" the it runs
Code:
default_application path/to/the/selected/file1
So, if you select multiple files and select "Open With 'Default Application'" the system will call
Code:
default_application path/to/the/selected/file1
default_application path/to/the/selected/file2
default_application path/to/the/selected/file3
So, this is a big problem for me, because I handle the concurrent processes from inside the program, so when another instance of the program is running, a warning message is appeared. So, each application's call will recognize the others as currently running applications and so it'll show the message. I'll end up with 3 Messages saying that another process of the program is running --_--'
My application handles multiple URLs this way:
Code:
myapp path/to/the/selected/file1 path/to/the/selected/file2 path/to/the/selected/file3
How can I make my code handle all these multiple instances at the same time? Everything I've tried fails, because everything I've tried requires a check from the first instance called, which is too slow and other instances come app and all together are warning about concurrent processes of the same program
So, how can I fix this? is it system depended, or can I do something with the code?
The way is to make your application recognize that there is already an instance running and make the new instance just forward a request to the first instance before dying :)
EDIT:
The way to do that is to have your first application instance behave as a server. The pseudo algo is something like :
start();
try_to_contact_master_server_instance();
if(no_master())
{
I_am_master();
start_listening_server_that_wait_for_requests();
}
else
{
send_request_to_master("open file path/to/the/selected/file1");
send_request_to_master("open file path/to/the/selected/file2");
send_request_to_master("open file path/to/the/selected/file3");
die();
}
handle_incoming_requests();
I hope it's clearer ? Tell me if you need more precisions ...
For the server part, you can do your own or use some software bus provided by the OS like dbus or whatever, but it makes your application dependent, of course.
my2c