Home > Software engineering >  Program at the end of the wrong ~ ~ about interprocess communications
Program at the end of the wrong ~ ~ about interprocess communications

Time:10-15

First of all thank you for your open posts of your little sister! Beginners MFC to achieve the win32 console application and use a named pipe interprocess communication between MFC, accused is transmitting data==
About 10 days, finally begun, but still did not want to come to the result,
First win32 application reads data from a binary file, save in the array, then need to pass through the pipe to the MFC,

MFC WM_PIPE inside my custom a news, and a message LOADDATA () function, this part of the code is as follows:
Void CMFCPIPEINDlg: : LOADDATA (WPARAM WPARAM, LPARAM LPARAM)
{
HANDLE hNamedPipe=CreateNamedPipe (
The TEXT (" \ \ \ \. \ \ pipe \ \ mypipe "),//the name of the pipe
PIPE_ACCESS_DUPLEX,//1 - way pipe, the server can only receive
PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT,//data as byte streams
2,//allows two instances
0,
0,
NMPWAIT_WAIT_FOREVER,//always wait
NULL);//use the default security attributes

If (INVALID_HANDLE_VALUE=hNamedPipe https://bbs.csdn.net/topics/={AfxMessageBox (TEXT (" CreateNamedPipe Failed. ")); return; }
The else AfxMessageBox (TEXT (" CreateNamedPipe Success. "));
AfxMessageBox (TEXT (" Waiting for the clinet to connect to the pipe... "));
if (! ConnectNamedPipe (hNamedPipe, NULL)) {
MessageBox (TEXT (" always connect a Named Pipe "));
The CloseHandle (hNamedPipe); return;
} the else AfxMessageBox (TEXT (" Connect Named Pipe "));
Short * pReadBuf=new short;
Memset (pReadBuf, 0, sizeof (short));
DWORD dwRead=0;
if (! ReadFile (hNamedPipe pReadBuf, sizeof (short), & amp; DwRead, NULL)) {
If (NULL!=pReadBuf) {delete (pReadBuf); PReadBuf=NULL; }
AfxMessageBox (TEXT (" Read the file failed!" ));
}
DisconnectNamedPipe (hNamedPipe);
The CloseHandle (hNamedPipe); }


Void CMFCPIPEINDlg: : OnBnClickedButton1 ()
{
//TODO: add the control notification handler code
This - & gt; PostMessageW (WM_PIPE, 0, 0);
}

The console code is as follows:
# define _CRT_SECURE_NO_WARNINGS
# define the CHUNK of 1024
#include
#include
#include
#include
#include


using namespace std;

Int main ()
{
Cstrings strPipeName=TEXT (" \ \ \ \. \ \ pipe \ \ mypipe ");
Cout & lt; <"Waiting for connecting Pipe... "& lt;
if (! WaitNamedPipe (strPipeName NMPWAIT_WAIT_FOREVER)) {
Cout & lt; <"Named pipe not exist!" }
The else cout & lt; <"Named pipe exist!"


HANDLE hNamedPipe=CreateFile (strPipeName, GENERIC_READ | GENERIC_WRITE, 0, NULL,
OPEN_EXISTING FILE_ATTRIBUTE_NORMAL, NULL);

If (INVALID_HANDLE_VALUE=hNamedPipe https://bbs.csdn.net/topics/=
{
Cout & lt; <"Create Pipe Failed!" }
The else cout & lt; <"Create Pipe Success!" The FILE * fp.
Fp=fopen (" C4. Ebm, "" rb");//open the file and check the error
If (fp==NULL)
{
Printf (" error!" );
The exit (0);
}

//calculate the file size
Int prev=ftell (fp);
The fseek (fp, 0 l, SEEK_END);
Int sz=ftell (fp);
Fseek (fp, prev, SEEK_SET);
//printf (" % d \ n ", sz);

//load the file (int16=short)
Unsigned short * array;
Array=(unsigned short *) malloc (sizeof (unsigned short) * sz/2);
Int res=fread (array, sizeof (unsigned short), sz/2, fp);
The fclose (fp);

//printf (" % d \ n ", res);

for (int i=0; i <1000; I++)
{
If (array [I] & gt;
=32768){
Array [I]=65536 - array [I];
//printf (" % u \ n ", array [I]);
}
//else
//printf (" % u \ n ", array [I]);
}

DWORD dwWRITE=0;
if (! WriteFile (hNamedPipe, & amp; Array, sizeof (short), & amp; DwWRITE, NULL))
{cout & lt; <"Read data failed!" Cout & lt; <"Read data success!" The CloseHandle (hNamedPipe);
Free (array);
system("pause");
Return (0);


}
First run the MFC to the interface

Confirmed to run the console program gets below==

Then the MFC will show pipeline establish success

Then the data transfer==when out of the box, unknown/(ㄒ o ㄒ)/~ ~

The great god can help me with a recruit not==I really no way out
Thank you again for greatly people read this topic! Little younger sister very grateful!
In addition there is a program can refer to: http://avidinsight.uk/2012/03/introduction-to-win32-named-pipes-cpp/#more-139
Thank you for your attention!

CodePudding user response:

for (int i=0; i 1000; I++) for (int I=0; i Project properties in __cdecl Link way

CodePudding user response:

Can switch socket transmission?

CodePudding user response:

Point has been interrupted, look at the call stack window API call relationship

CodePudding user response:

Collapsed in the pop-up dialog box, press the corresponding button to enter debugging press Alt + 7 key to view the Call Stack, namely "the Call Stack" from the inside to the following out of from the inner to outer function Call history, double-click a row to the cursor to the Call of the source code or assembly instruction, don't understand when double click on the next line, until we can read ,

CodePudding user response:

Error is a function "engagement" is wrongnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related