NO

Author Topic: error #2048: Undeclared identifier 'true' (line 29 of my code, the first return)  (Read 6398 times)

EdPellesC99

  • Guest
  
   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






« Last Edit: January 31, 2010, 03:01:40 AM by EdPellesC99 »

iZzz32

  • Guest
If you really want to return true instead of 0 in int main, just #include <stdbool.h>.

EdPellesC99

  • Guest


  Thanks for the reply, I tried it. The error changed to: POLINK: error: Unresolved external symbol '_WinMain@16'.

   .... Ed

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2107
Re: error #2048: Undeclared identifier 'true'
« Reply #3 on: January 31, 2010, 06:36:03 PM »
Change projects linker option Subsystem type to Console from menu Projects -> Projects options.. -> Linker -> Type.
May the source be with you

EdPellesC99

  • Guest
 ;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" ! )