Solved

Example of IPC in VC++ .Net

Posted on 2004-09-16
9
727 Views
Last Modified: 2012-08-14
Hello all,

I have an assignment to make a board game in VC++ .Net  , I am required to make GUI and create 3 processes Master, player1 and player2....

I have been looking online for IPC and have found some examples but all went over the top of my head....

I would appreciate if someone could give me an example explaining...

create process ( i.e. initialize player1 from master )
pass data ( structure ) to player1
receive feedback from player1
pass data to player2 ( it has already been initialized before i.e after player1)
receive feedback from player2
pass data to player1( what will happen to player1 in the mean time? )

Thanks a lot
0
Comment
Question by:hatimad
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 6

Expert Comment

by:Svetlin_Panayotov
ID: 12082103
http://www.codeproject.com/internet/renju.asp
This sample contains at least some base classes that could help you.It's direct connection - but with just few modifications in CListenSocket and CClientSocket you can use it for your game.

Svetlin
0
 
LVL 6

Expert Comment

by:Svetlin_Panayotov
ID: 12082176
Oh...and another - from CodeProject again http://www.codeproject.com/internet/WinBattleArticle.asp
0
 
LVL 16

Expert Comment

by:nonubik
ID: 12082322
IPC does not resume only to socket communications. There are also pipes, mapped files, mailslots, rpc, etc.
A good sample to start is http://www.codeproject.com/threads/ipcworkshop.asp . It explains 5 of the IPCs: clipboard, file mapping, mailslots, named pipes and sockets.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 16

Expert Comment

by:nonubik
ID: 12082328
0
 

Author Comment

by:hatimad
ID: 12084866
Thanks for your comments, I will go through the links and get back
0
 

Author Comment

by:hatimad
ID: 12088619
ok,

I tried those links but all of them seems to have one or other problem first 2 are too complicated and almost all has problems compiling on .net 2002.

I found this link

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/creating_named_shared_memory.asp 

which has working example.

But the problem now is, when I try to modify it to use structure, it gives me errors....

could anyone please show me an example with simple structure in it?

like how do I implement this structure insted of text?

struct {
      int MsgNo;
      String Msg;
}

Thank you
0
 
LVL 16

Expert Comment

by:nonubik
ID: 12095573
Having

typedef struct _Msg {
      int MsgNo;
      char *Msg;
}MSG;

MSG MyMessage;

//fill it
.....
//first process

CopyMemory((PVOID)pBuf, (void *)&MyMessage, sizeof(MyMessage.MsgNo) + strlen(MyMessage.Msg));


//second process
void *pBuf
 pBuf = MapViewOfFile(hMapFile,    // handle to mapping object
               FILE_MAP_ALL_ACCESS,  // read/write permission
               0,                    
               0,                    
               BUF_SIZE);      

MSG MyMessage;

strncpy(&(MyMessage.MsgNo), (char *)pBuf, sizeof(iMsgNo));
MyMessage.Msg = new char[strlen((char*)(pBuf+sizeof(int)))];
strcpy(MyMessage.Msg, (char*)(pBuf+sizeof(int)));

The idea is that you must know the length of the buffer that is passed between the 2 processes, both on sending and on receiving.
0
 

Author Comment

by:hatimad
ID: 12095890
Hello,

Thanks for the example, I have got the shared meomory part working just like you have pointed out.

At the moment, after I map data from process1 to memory file, I have to manually start using data in process 2

How do I inform process 2 to start using the data after process 1 has copied it to the memory file autmetically??

0
 
LVL 16

Accepted Solution

by:
nonubik earned 500 total points
ID: 12099971
You can create a mutex to synchronize the processes. The first process creates a mutex after it writes to mapped file. The second proces tries to open the mutex. It will only succeed after the mutex was created. See "Using Named Objects" for more info: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/using_named_objects.asp
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Cchar * Concating 7 96
How to change toolbar  runtime 3 467
Need help with a query 7 55
Implementing a ResolveEventHandler in C++ 13 154
The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question