我想在VC++ 6应用程序和C#应用程序之间进行双向通信.我正在使用命名管道.在我的C++代码中,我可以从C#客户端读取消息,但随后服务器"死机",我必须重新启动它.
我想要做的是让C#应用程序连接到C++应用程序,请求状态,然后C++应用程序关闭并检查状态,然后返回"忙"或"空闲".
我不能把任何东西写回C#客户端,因为它说连接已经关闭.我已经评论过的一些事情是我已经尝试过的事情.
C++代码(作为线程启动)
UINT CNamedPipe::StartNamedPipeServer()
{
LPTSTR lpszPipename = "\\\\.\\pipe\\SAPipe";
HANDLE hPipe;
BOOL flg;
DWORD dwWrite,dwRead;
char szServerUpdate[200];
char szClientUpdate[200];
hPipe = CreateNamedPipe ( lpszPipename,
PIPE_ACCESS_DUPLEX,
PIPE_TYPE_MESSAGE |
PIPE_READMODE_MESSAGE |
PIPE_NOWAIT, //changed from nowait
PIPE_UNLIMITED_INSTANCES, // max. instances
BUFSIZE, // output buffer size
BUFSIZE, // input buffer size
PIPE_TIMEOUT, // client time-out
NULL); // no security attribute
if (hPipe == INVALID_HANDLE_VALUE)
return 0;
ConnectNamedPipe(hPipe, NULL);
while(m_bServerActive) //This seems to work well ....
{
//Read from client
flg = …Run Code Online (Sandbox Code Playgroud)