CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 32

Threaded View

  1. #23
    Join Date
    Sep 2010
    Posts
    15

    Re: CreateFile Failed problem

    Code:
    bool Serial::connect()
    {
      if (mConnected)
      {
        printf("You are already connected, please disconnect first\n");
        return false;
      }
      
      COMMTIMEOUTS cto;
      DCB dcb;
      char parity, stop_bits;
      int speed;
    	 	 
      if (mFd != INVALID_HANDLE_VALUE && !CloseHandle(mFd)){
        printf("Can't close comm port");
        return false;
      }
     
      mFd = CreateFileA(mDevice,
    		    GENERIC_READ|GENERIC_WRITE,
    		    0,
    		    NULL,
    		    OPEN_EXISTING,
    		    0,
    		    NULL);
    	 
      if(mFd == INVALID_HANDLE_VALUE)
      {
        printf("CreateFile on %s failed with error code: %d \n"
          , mDevice
          , GetLastError( ) );
    	  char port[64];
        strcpy(port, "\\\\.\\");
        strcat(port, mDevice);
        mFd = CreateFileA(port,
    		      GENERIC_READ|GENERIC_WRITE,
    		      0,
    		      NULL,
    		      OPEN_EXISTING,
    		      0,
    		      NULL);
    		 
        if(mFd == INVALID_HANDLE_VALUE){
    	    printf("CreateFile on %s failed with error code: %d \n"
            , port
            , GetLastError( ) );
    	printf("CreateFile Failed \n");
          return false;
        } 
      }
    "CreateFile Failed
    CreateFile on C:\Documents an=failed with error code: 2
    CreateFile on \\.\C:\Documents an=failed with error code: 2"

    Why did it not show the full path?
    Last edited by wklove2003; September 10th, 2010 at 12:06 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured