Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
in the name of allah

have a good time

i have two application and i want to make a connection between them.
can you tell me the solutions for this?

i've tested bellow methods.

can you guide me to do this?

thanks

What I have tried:

for example the 1st way is that we work on a file and first app send it's message to the file and second app receive message from file. but this method it isn't secure and we should use the encryption & decryption algorithm for the files'data.

the 2nd way that i know is the "SendMessage" to each other. this method has it's problems too.
Posted
Updated 11-Apr-16 14:18pm
Comments
Sergey Alexandrovich Kryukov 11-Apr-16 11:13am    
First of all, avoid SendMessage by all means. Consider sockets, named pipes, some higher-level messaging system.
—SA
Mohibur Rashid 11-Apr-16 18:31pm    
This would be the finest solution
Sergey Alexandrovich Kryukov 11-Apr-16 20:20pm    
All right, thank you, but it would take a lot more text to write. :-)
After all, I added important detail and put it as Solution 2, please see.
—SA

What you are looking for is known as IPC (Inter-process communication - Wikipedia, the free encyclopedia[^]).

For Windows, see Interprocess Communications (Windows)[^].
 
Share this answer
 
Comments
Mahdi Nejadsahebi 14-Apr-16 0:06am    
Thanks dear Jochen.
i read your post and got useful information about IPC.
i think i use the send/get message for my project.

but can you tell me how can i share a part (address) of RAM between two applications?
Jochen Arndt 14-Apr-16 2:59am    
There is no solution to share normal memory.

You can use memory-mapped files: https://msdn.microsoft.com/en-us/library/windows/desktop/aa366551%28v=vs.85%29.aspx.

You may also use global memory blocks. These are used by clipboard and Drag&Drop operations. See https://msdn.microsoft.com/en-us/library/windows/desktop/aa366574%28v=vs.85%29.aspx.
When using global memory with different applications, call GlobalAlloc with flags GMEM_MOVEABLE. This requires using GlobalLock() / GlobalUnlock() to get exclusive access.
Please see my comment to the question.

SendMessage suggests that you want to develop on Windows. Only just forget SendMessage.

One option is using sockets. This is how it looks on Windows:
Windows Sockets 2 (Windows)[^],
Getting Started with Winsock (Windows)[^],
Creating a Basic Winsock Application (Windows)[^].

In most cases, you have to work at the transport layer, using TCP. This CodeProject article can also be useful:
Programming Windows TCP Sockets in C++ for the Beginner[^].

I hope you understand that sockets is the universal interface available on nearly all platforms which can be used on the same machine or a network. Another facility of this sort is named pipes:
CreateNamedPipe function (Windows)[^],
ConnectNamedPipe function (Windows)[^],
CallNamedPipe function (Windows)[^];
for examples, see also:
Multithreaded Pipe Server (Windows)[^],
Named Pipe Client (Windows)[^].

Now we can discuss higher-level communications. Actually, I'm not sure what do you mean by "C++". If this includes C++/CLI, you can use .NET "classic" remoting or WPF. Both approaches are abstracted from the nature of channel, which can be replaced and include sockets and named pipes; also, virtually any higher-level protocol can be plugged in.

One such higher-level facility is Microsoft message-oriented MSMQ:
Microsoft Message Queuing — Wikipedia, the free encyclopedia[^],
Message Queuing (MSMQ)[^].

There are a lot more systems and protocols, at different levels of standardization covering different subset of platforms. For more detail, please see: Message queue — Wikipedia, the free encyclopedia[^].

Certainly, there is a lot to learn. Probably, you need to learn basics first, do some minimalistic prototyping, and then decide what best fits your ultimate purposes.

The architecture of the application-level systems with communication is not very trivial task. You need to make it efficient, importantly, avoid polling (pull technology) and focus on push technology, to avoid wasting resources and design responsible system. One of the most useful and productive paradigms is published-subscriber architecture. And so long…

Please see some of my past answers:
an amateur question in socket programming[^],
How Do I Get To Know If A A Tcp Connection Is Over[^],
Application 'dashboard' for website accounts[^],
How Do I Control My Client Computers By Server Computer[^].

These answers are not specifically for C++, but they can give you a good idea what is it all about.

See also:
Pull technology — Wikipedia, the free encyclopedia[^],
Push technology — Wikipedia, the free encyclopedia[^],
Client–server model — Wikipedia, the free encyclopedia[^],
Publish–subscribe pattern — Wikipedia, the free encyclopedia[^].

—SA
 
Share this answer
 
v2
Comments
Mahdi Nejadsahebi 14-Apr-16 0:08am    
wow ! . your explanations are complete.
i really thank you for helping and the time you have spent.
Sergey Alexandrovich Kryukov 14-Apr-16 1:12am    
You are very welcome.
Good luck, call again.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900