[jcifs] NamedPipe question
Jorg Schorr
Jorg.Schorr at ctp.com
Wed Oct 8 18:25:53 EST 2003
Hello,
I need to connect to an existing program (I do not have the source
code) on Windows written in C++ using NamedPipes to communicate. I have
this C++ code snippet which works, but when I try to do the same with
jCIFS it fails . Actually I tried to open the NamedFile as given in the
jCIFS JavaDoc when it has to be opened through CreateFile, but when I do
this it fails when I try to write on it, saying "File not found."
Any help is welcome.
Thanks.
OVERLAPPED ovWr;
OVERLAPPED ovRd;
HANDLE hEventWr;
HANDLE hEventRd;
PSECURITY_DESCRIPTOR pSD;
pSD = (PSECURITY_DESCRIPTOR) LocalAlloc(LPTR,
SECURITY_DESCRIPTOR_MIN_LENGTH);
if (!InitializeSecurityDescriptor(pSD, SECURITY_DESCRIPTOR_REVISION))
{
LocalFree((HLOCAL) pSD);
return -1;
}
if (!SetSecurityDescriptorDacl(pSD, TRUE, (PACL) NULL, FALSE)) {
LocalFree((HLOCAL) pSD);
return -1;
}
SECURITY_ATTRIBUTES sa;
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = pSD;
hEventRd = CreateEvent(NULL, TRUE, FALSE, NULL);
hEventWr = CreateEvent(NULL, TRUE, FALSE, NULL);
memset(&ovWr, 0, sizeof(ovWr));
ovWr.hEvent = hEventWr;
h = CreateFile(target, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ |
FILE_SHARE_WRITE, NULL, CREATE_NEW, FILE_FLAG_OVERLAPPED, NULL);
if (h == INVALID_HANDLE_VALUE) {
printf("Error: handle: %u\r\n", GetLastError());
return 0;
}
int result = WriteFile(h, send_buf, bytesRead, &bytesRead, &ovWr);
if (!result) {
int error = GetLastError();
if (error == ERROR_IO_PENDING) {
error = WaitForSingleObject(hEventWr, (DWORD)-1);
if (error != WAIT_OBJECT_0) {
printf("Error: writing: %u\r\n", GetLastError());
return 0;
}
}
}
memset(&ovRd, 0, sizeof(ovRd));
ovRd.hEvent = hEventRd;
bytesRead = 220;
result = ReadFile(h, recv_buf, bytesRead, &bytesRead, &ovRd);
if (!result) {
int error = GetLastError();
if (error == ERROR_IO_PENDING) {
error = WaitForSingleObject(hEventRd, (DWORD)-1);
if (error != WAIT_OBJECT_0) {
result = GetOverlappedResult(h, &ovRd, &bytesRead, FALSE);
if (!result) {
printf("Error: writing: %u\r\n", GetLastError());
return 0;
}
}
}
}
bytesRead = 220;
result = (outFile != NULL && WriteFile(outFile, recv_buf, bytesRead,
&bytesRead, NULL));
if (!result) {
printf("Error: failed to write to outFile\r\n");
printf("Success: operation performed successfully\r\n");
}
CloseHandle(h);
-------------- next part --------------
HTML attachment scrubbed and removed
More information about the jcifs
mailing list