C++ How to make two programs communicate? - c++

Question: What is the best way to make two programs (both running on the same computer) communicate and interact? (Windows, C++)
Theoretical situation:
On a Windows PC, I have a 3rd party software that you use to do stuff (like open/edit/save files...it's not really important). This 3rd party software has an available C++ SDK so you can develop plugins for it.
I develop a separate standalone Windows C++ program (most likely using Qt) with a GUI. This program is made to run on the same Windows computer as the 3rd party software. This program would act as a remote control or sender.
Using the 3rd party software's SDK, I develop a tiny plugin for the 3rd party software. This program acts as a receiver, so that my Qt GUI can send commands that this plugin would receive and thus remote control the 3rd party software accordingly.
So for a basic example, I could press a button on my standalone GUI that would communicate with the plugin that would then open a specified file in the 3rd party software.
What I'm essentially looking for is to develop standalone software that would communicate back and forth with a plugin that I would develop for the 3rd party software.
What is the best approach to this? I really have no clue where to start or what to look at. Are there common C++ libraries that make this type of thing easy?
I'm relatively new to C++ and very new to Qt, so please try to elaborate. Please don't just say "Use Shared Memory" or something like that cause I'm not gonna know exactly what you are talking about.
The program would NOT be run on a separate computer, so no network stuff is necessary here I don't think.
Some questions I was thinking about:
What if user has multiple copies of 3rd party software open at the same time. How does my standalone software know which one to communicate with?
If I already have my standalone software running and open the 3rd party software, does the plugin somehow have to register or find my standalone software to communicate with it?
If I already have the 3rd party software running and then open my standalone software does it have to scan for the plugin to see if its running or how does it find it?
Any help would be greatly appreciated. I've done a search on the topic on SO but didn't see many questions for C++ specifically and most of them didn't have many answers or weren't very clear or didn't specifically refer to software communication with a plugin for a 3rd party program.

there are many solutions with many pros and cons. you will have to do some reading on each to work out which is best for you. no solution is best for everyone
here is a good starting place http://msdn.microsoft.com/en-us/library/aa365574(v=vs.85).aspx

Honestly, I'd most likely take the network-based approach. It decouples the standalone software and the plugin and as such, you could easily hook your plugin into any number of other utility programs or scripts as long as the communication protocol matches.
So, I'd probably develop the plugin to act as a server, receiving commands and responding with statuses (hey, you could even follow the HTTP standard if you really wanted to ;)).
And if you ever wanted to do cross-machine communication, it comes for free :)
Of course, depending on the software and the usage, I'd encrypt the communication.

If you're using Qt, I believe it has the notion of Plugin: How to Create Qt Plugins
Otherwise, COM works fine. With C++ , I would use the ATL library, but there is also COM support in Qt.
If you want to go more low level, I would use sockets or named pipes (since you're working with Windows)

I'd go for sockets to establish a communication between your remote control application and the server app.
You'll find lots and lots of information by searching these keywords here on SO: IPC, RPC, sockets.

Related

How to use WebRTC in a C++ application?

I'm trying to write a C++ command line program for peer-to-peer file transfer. My idea is to establish a connection with another machine, and send file data directly. My target platform is Windows, but interoperability with Linux and MacOS would be nice. I want this program to be standalone and not require a web browser.
I did some research and it seems that WebRTC would fit the bill, but I can't find much information on using it with C++.
Is it possible to build a standalone executable that utilizes WebRTC without requiring users to download any dependencies in order to use my program?
As the name suggests - to have the "RTC", it requires "Web" component, either in form of browser or a library.
The C++ library is quite huge and it's not a trivial task to understand and write it in a short period. Browser provides APIs in form of JavaScript calls, which are relatively easier to implement.
There might be commercial APIs in C++ available over internet.

signal/Textsecure bindings for c/c++?

I am trying to create a signal/textsecure client using qt and C++, however i cant seem to fibd any C++ bindings for it.
the only bindings i can find are for Go (https://github.com/nanu-c/textsecure/)
is there any way to connect C++ with signal?
edit:
i wanted to clarify some things:
-im talking about the messaging app called Signal (https://signal.org)
-i am trying to write an app for ubuntu touch and am developing on manjaro linux.
On Linux or Unix, you probably want to communicate with other remote applications using some communication protocol, such as HTTP or HTTPS or SOAP or JSONRPC or ONCRPC. Of course read about socket(7) and before that Advanced Linux Programming then about syscalls(2). Consider reading a textbook on Operating Systems
Be sure to study the source code related to Signal. Read their technical documentation.
You surely need to understand the details. So take a few days or weeks to read more about them.
If you want to use some web service, you need to read and understand its documentation and when and how you are allowed to use it. There could be legal or financial issues.
Then you might use HTTP related libraries (e.g. Wt or libonion server side, and libcurl or curlpp client side).
See also in April 2020 the ongoing HelpCovid free software project (for Linux), at least for inspiration. We are coding it in C++.
after a little more digging i found that textsecure bindings are now renamed to libsignal.
after finding that out i found a lib for c/c++
https://github.com/signalapp/libsignal-protocol-c

Use Go within a Qt C++ project

Is it possible to use a Go API in a Qt C++ project?
I would like to use the following Google API written in Go: https://cloud.google.com/speech-to-text/docs/reference/libraries#client-libraries-install-go
Is it possible to use a Go API in a Qt C++ project?
It could be possible, but it might not be easy and would be very brittle to run Go and Qt code in the same process, since Go and Qt have very different thread (goroutine) and memory models.
However, Go has (in its standard library) many powerful packages to ease the development of server programs, in particular of HTTP or JSONRPC servers.
Perhaps you might consider running two different processes using inter-process communication facilities. Details are operating system specific. I assume you run Linux. Your Qt application could then start the Go program using QProcess and later communicate with it (behaving as a client to your Go specialized "server"-like program).
Then you could use HTTP or JSONRPC to remotely call your Go functions from your Qt application. You need some HTTP client library in Qt (it is there already under Qt Network, and you might also use libcurl) or some JSONRPC client library. Your Go program would be some specialized HTTP or JSONRPC server (and some Google Speech to Text client) and your Qt program would be its only client (and would start it). So your Go program would be some specialized proxy. You could even use pipe(7)-s, unix(7) sockets, or fifo(7)-s to increase the "privacy" of the communication channel.
If the Google Speech to Text API is huge (but it probably is not) you might use Go reflective or introspective abilities to generate some C++ glue code for Qt: go/ast, go/build, go/parser, go/importer, etc
BTW, it seems that Google Speech to Text protocol is using JSON with HTTP (it seems to be some Web API) and has a documented REST API, so you might directly code in C++ the relevant code doing that (of course you need to understand all the details of the protocol: relevant HTTP requests and JSON formats), without any Go code (or process). If you go that route, I recommend making your Qt (or C++) code for Google Speech to Text some separate free software library (to be able to get feedback and help from outside).

IPC for Windows Universal APP to enable calling all Win32 APIs

I am developing an application on Windows 10 that interacts with custom device drivers, the NTFS filesystem and DirectX 12. The app is a Windows Universal App written in C++, WRL, XAML and DirectX. For DirectX I have chosen a SwapChainPanel control and the DirectX portion of the app works great. The app is Sideloaded so I have a bit more freedom than an app that needs to go through the store
Unfortunately the Windows Universal Apps have a number of restrictions with regards to API calls. WinRt APIs are favored.
Here are a list of WinRt APIs to call to replace Win32 APIs:
https://msdn.microsoft.com/en-us/library/windows/apps/hh464945.aspx
In addition Windows Universal Apps can call Win32 APIs that are partitioned to the application (however not the ones partitioned to the desktop) as indicated in the documentation of each function and in the header file. Here is a link:
https://msdn.microsoft.com/en-us/library/windows/apps/br205762.aspx
In addition the Winsock APIs are now allowed from Windows Universal Apps
However I am still left without my favorite (and necessary APIs)
CreateFile()
ReadFile()
WriteFile()
DeviceIoControl()
CloseHandle()
In particular I need to read and write files to all locations without user interaction (and not to the locations restrict by the Windows Universal App Sandbox). In addition I need to send IOCTLs to my multiple device drivers.
I could abandon Windows Universal Apps and go with WPF. However I have a touch intensive application and I need touch to work really well. In addition I have to wonder about the lack of fixes and commitment to WPF on the behalf of Microsoft. I have considered other UI frameworks but none have been as promising as a Windows Universal App.
Microsoft has allowed two paths in Windows 10 for Universal Apps that will allow calling all Win32 functions (For side loaded apps).
Brokered Windows Runtime Component
and IPC though TCPIP
I have written a brokered windows runtime component and it works well. However the solution requires a C# app to be in the mix and I do not need/want that as I need fast load times of the app and do not want to pull the CLR in.
The next option is IPC through TCPIP. I would use Fast TCP Loopback as explained in the blog post: Fast TCP Loopback Performance and Low Latency with Windows Server 2012 TCP Loopback Fast Path. I would link to it but I am at my (very generous) two link limit for a first post.
I have a couple of questions:
1) If I go this route should I place the IPC between the XAML controls/buttons and the rest of the App? This would allow the rest of the app to be strictly Win32. Or should I just place the IPC between the app and calls to the specific functions I need that fall outside of the those allowed by Win32.
2) I have looked for a library or paper that has code and/or ideas for implementing IPC with TCPIP. However so far the papers that talk about IPC with TCPIP seem to simply describe winsock programming which is something I already know how to do. I would enjoy coding up IPC but would prefer a solution that has been tested. This needs to work flawlessly and I would rather have code with some time on it. Has anyone used or heard of code and or a design for IPC over TCPIP that is available to share?

Resources for Programming the Linux X-Server

Are there any out there that are easy to get ahold of? Preferably free, as I don't have any money to spend right now.
What I'm trying to Accomplish
Basically, I'm writing a multi-platform application in native C/C++, and now that I have Linux installed, I feel as though I'm truly ready to make the "multi-platform" development go. Before anyone says "use SDL" or "Qt", note that I'm doing this for an application which I plan to go commercial with (Qt costs money for commercial applications). While SDL is good, I'm also looking to learn about window managers in general. I feel as though the best way to learn how to communicate directly with the operating system is to write the application yourself.
So, are there any resources out there?
First of all X-Windows has nothing to do with Linux.
X-Windows is both a graphical protocol and a GUI system built up around it. X runs on most OSes including Windows and Mac. The most typical scenario is for an X application to run on a multiuser computer running a UNIX-like OS (for instance Linux) and for the users to interact with it using an X-server which runs on either an X-terminal or a desktop OS. The X-Server is a standard piece of the X-System. If you install an X-Server on Windows then you will be able to interact with graphical applications running on one or more other computers.
It sounds like you want to focus on building the X applications, not the device drivers or the server or any other part of the X-system. Linux is as good a choice as any, but the books and documents that you need were likely written using Solaris or BSD UNIX. But it's the same API.
Since X has been widespread since at least the early 90's, look for books in secondhand shops and university jumble sales. Advertise on Craigslist for X related books.
The lowest level API for X is called Xlib. Toolkits like GTK and QT are layered on top of this so studying their code is a good way to learn how to do things. But there is also something called the X-Toolkit that runs over Xlib and used to be the foundation layer for GUI toolkits like Motif and others. If I were you I would start with X-Toolkit, to get familiar with all the component parts of X and how they interact. For instance, it will take you a while to get used to the fact that a window manager which manages the windows on an X-Server display, doesn't run on the X-server but runs on a remote system. Or that you can have apps running on Linux and OS/X and Solaris all displaying their windows on the X-server on a single Windows box.
Google X Toolkit intrinsics to get all kinds of info including free reference manuals.
As you read more about it you will come across a lot of other unique terms that you can google to get additional info and a broader perspective. Don't spend too much time with old toolkits like Athena Widgets or Motif.
Since there were more people programming X in the early days of the Internet than today, the USENET FAQs are still a good source of introductory tips, e.g. http://www.faqs.org/faqs/Xt-FAQ/
You can write your app as a server in C. Call it Engine. No need to think about the User Interface. After that you can create interface in Qt. The communication protocol will be public (or private) and your Qt application will be open-source. Later if you like you can create many more interface to your application. Such as web interface, Gnome interface, C#.NET interface etc.