windows - Pipe communication C++ -


I'm writing two little C + apps that should be communicated first, there will be one such service, In time the user should be alerted for some. Since I can not create a service window I have created the app to be two different executables.

Services will use an indicator to communicate.

To send text messages only to the need indicator, a balloon will appear in the system tray.

I am trying to use designated pipes and I think I'm almost there, but not quite. What I have so far:

The indicator side:

  m_hInPipe = CreateNamedPipe (L ". \\\\ \\ pipe \\ nhsupspipe", PIPE_ACCESS_INBOUND, PIPE_WAIT , 1, 1024, 1024, 60, NULL);  

I mean nhsupspipe named a pipe, created an inbound pipe

in the service side:.!

  If (WriteMy_HOutPipe, "My Message to User?", 23, & escritos, & amp; o) std :: cout & lt; & Lt; "Error:" & lt; & Lt; GetLastError ();  

Debugging I can see that it is all right, the pipe is created and writeFile writes its 23 bytes to pipe

My question is:. How, in the Notifier side, will I be able to read these bytes? Has any message been sent in the process? Do I have to write a handler for a pipe? anything?

A few simple snippets from the customer (your service) & amp; Server (Notifier) ​​[ Note: This was adapted from a project I did some time ago, which in turn was made by MSDN samples "CreateNamedPipe & amp; Co ]:

The server side:

  handle Acpeep = INVALID_HANDLE_VALUE; bool Biknekt = false; hPipe = CreateNamedPipe (L "\\\\ \\ pipe \\ nhsupspipe.", PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, sizeof (message), 0, 0, failed to void); // pipe? If (hPipe == INVALID_HANDLE_VALUE) client to connect {return -1;} // Raticsha or, if it succeeds, then // function returns a non-Zorro value. If the function // returns void, so GetLastError ERROR_PIPE_CONNECTED. BConnected = ConnectNamedPipe (Acpiip, null)? True: (GetLastError () == ERROR_PIPE_CONNECTED); if (Biknekt happened) {while (true) {unsigned long Ulbaitsred = 0; // Read client request pipes. Bool bReadOk = Reedfail (Acpiip, and message size (message), and amp; ulBytesRead , NULL); // Jail failed to read [error or client closed connection] if break! (BReadOk || ulBytesRead == 0); // All OK, process received message}} and {// the client could not connect, so turn off the pipe shut down (hpip); } Return 0;  

Customer:

Handle HPP = INVALID_HANDLE_VALUE; // named pipe handle hPipe = make CreateFile (L "\\\\ \\ pipe \\ nhsupspipe.", GENERIC_READ | GENERIC_WRITE, 0, zero, OPEN_EXISTING, 0, null); // If everything sets mode in correct message mode (INVALID_HANDLE_VALUE! = HPipe) {DWORD dwMode = PIPE_READMODE_MESSAGE; // If this fails (set NamedpipHandleState (HPP, and Doom, Faucet, Faucet)) {CloseHandle (HPP); Return -1; }} Unsigned long ulBytesWritten = 0; Bool bWriteOk = WriteFile (HPP, (LPCVOD) and message, size (message), and amp; ulBytesWritten, NULL); // Check if the writing was okay (! BWriteOk || ulBytesWritten & lt; sizeof (message)) {return -1; } // Written OK Return 0;

The above Message is a structure that will be your message, which you may want.

The client (service) in your scenario will probably be up & amp; To run before the server (notifier), you will need any kind of renection strategy on the client side.

And on a slightly different note, you should carefully consider what Mr. Osterman said (even not anything else but because she is Larry Ostroman).


Comments

Popular posts from this blog

Is there an open source WebSockets (JavaScript) XMPP library? -

java - Is there an object like a "Set" that can contain only unique string values, but also contain a count on the number of occurrences of the string value? -

iphone - How do I make a UIPickerView in a UIActionSheet -