C++ DLL 파일에서 파이프를 통해 C# pip 서버로 데이터를 보내려고합니다. 서버가 이미 프로그래밍되어 있고 C# 클라이언트로 데이터를 올바르게 가져올 수 있습니다.C++ NamedPipeClientStream 데이터 보내기
내 간단한 C# 클라이언트 코드 :
System.IO.Pipes.NamedPipeClientStream pipeClient = new System.IO.Pipes.NamedPipeClientStream(".", "testpipe", System.IO.Pipes.PipeDirection.InOut, System.IO.Pipes.PipeOptions.None);
if (pipeClient.IsConnected != true) { pipeClient.Connect(); }
StreamReader sr = new StreamReader(pipeClient);
StreamWriter sw = new StreamWriter(pipeClient);
try
{
sw.WriteLine("Test Message");
sw.Flush();
pipeClient.Close();
}
catch (Exception ex) { throw ex; }
}
는 그러나, 나는 C에서이 클라이언트를 실현 함께하지 않는 ++. 어떤 헤더 파일이 필요합니까? 간단한 예를 들어 주시겠습니까? 고맙습니다!
편집 : 답장을 보내 주셔서 감사합니다. 그것을 테스트하기 위해, 나는 C++ 프로그램을 만든 다음 지금 컴파일 : 나는 그것을 실행할 때 (파이프 == INVALID_HANDLE_VALUE)는 사실이다 그러나
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
HANDLE pipe = CreateFile(
L"testpipe",
GENERIC_READ, // only need read access
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL
);
if (pipe == INVALID_HANDLE_VALUE) {
// look up error code here using GetLastError()
DWORD err = GetLastError();
system("pause");
return 1;
}
// The read operation will block until there is data to read
wchar_t buffer[128];
DWORD numBytesRead = 0;
BOOL result = ReadFile(
pipe,
buffer, // the data from the pipe will be put here
127 * sizeof(wchar_t), // number of bytes allocated
&numBytesRead, // this will store number of bytes actually read
NULL // not using overlapped IO
);
if (result) {
buffer[numBytesRead/sizeof(wchar_t)] = '?'; // null terminate the string
// wcout << "Number of bytes read: " << numBytesRead << endl;
// wcout << "Message: " << buffer << endl;
} else {
// wcout << "Failed to read data from the pipe." << endl;
}
// Close our pipe handle
CloseHandle(pipe);
system("pause");
return 0;
return 0;
}
. 디버깅을 통해 DWORD err = GetLastError(); 서버가 실행 중이지만 값은 2입니다. 아무도 아이디어가 있습니까?
안녕하세요 jmihalicza, 답장을 보내 주셔서 감사합니다! 나는 지금 나의 입장 포스트를 편집했다. 내가해야 할 일이 뭔지 알아? – user1956123