Pelles C forum
Pelles C => General discussions => Topic started by: EdPellesC99 on January 31, 2010, 02:57:32 AM
-
Hi,
I am trying to learn about the named pipe funtion. I found this code, I want to prove I can compile it. I am not able to compile with Pelles C.
I can however compile this .c program with CodeBlocks and the MinGW compiler, without error.
I am sure I am doing something wrong, and would appreciate any tips.
Here is the code:
#include <windows.h>
#include <stdio.h>
#define BUFSIZE 1024
#define PIPE_TIMEOUT 5000
int main()
{
BOOL fConnected;
LPTSTR lpszPipename = "\\\\.\\pipe\\SamplePipe";
CHAR chRequest[BUFSIZE];
DWORD cbBytesRead;
BOOL fSuccess;
HANDLE hPipe;
hPipe=CreateNamedPipe(lpszPipename,
PIPE_ACCESS_DUPLEX, // read/write access
PIPE_TYPE_MESSAGE | // message type pipe
PIPE_READMODE_MESSAGE | // message-read mode
PIPE_WAIT, // blocking mode
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 true;
}
for (;;)
{
// Trying connectnamedpipe in sample for CreateNamedPipe
// Wait for the client to connect; if it succeeds,
// the function returns a nonzero value. If the function returns
// zero, GetLastError returns ERROR_PIPE_CONNECTED.
fConnected = ConnectNamedPipe(hPipe, NULL) ?
TRUE : (GetLastError() == ERROR_PIPE_CONNECTED);
if (fConnected)
{
fSuccess = ReadFile (hPipe, // handle to pipe
chRequest, // buffer to receive data
BUFSIZE, // size of buffer
&cbBytesRead, // number of bytes read
NULL); // not overlapped I/O
chRequest[cbBytesRead] = '\0';
printf("Data Received: %s\n",chRequest);
if (! fSuccess || cbBytesRead == 0)
break;
FlushFileBuffers(hPipe);
DisconnectNamedPipe(hPipe);
}
else
// The client could not connect in the CreateNamedPipe sample, so close the pipe.
CloseHandle(hPipe);
}
CloseHandle(hPipe);
return 1;
}
//=======================================================
Thank you very much. Ed
-
If you really want to return true instead of 0 in int main, just #include <stdbool.h>.
-
Thanks for the reply, I tried it. The error changed to: POLINK: error: Unresolved external symbol '_WinMain@16'.
.... Ed
-
Change projects linker option Subsystem type to Console from menu Projects -> Projects options.. -> Linker -> Type.
-
;D ;D ;D
Great, Worked like a champ.
Thanks so much,
I just started using Pelles C last week, and had not even found Projects / Project Options as the place for Compiler and Linker Settings (not that I would have discovered your solution on my own). I even found where I can indicate a smaller size file in the Compiler Settings (which I needed!).
Again, Timo thanks for the super help.
........ Ed (I like the cat pic, I have a cat just like her/him "Boots" ! )