WaitCommEvent ERROR_INVALID_PARAMETER 
Author Message
 WaitCommEvent ERROR_INVALID_PARAMETER

Could someone please help. I'm getting a ERROR_INVALID_PARAMETER error from
GetLastError
after calling WaitCommEvent the sencond time.

I have no idea what causes this error.

Francois



Tue, 14 Dec 2004 00:32:41 GMT  
 WaitCommEvent ERROR_INVALID_PARAMETER
Francois,

    You should NOT be using GetLastError in your code.  The reason for this
is that the .NET runtime will rely on Win32 API function calls that might
set this.  What you want to do is use the static GetLastWin32Error method on
the Marshal class, and make sure that the SetLastError flag in the DllImport
attribute for your declaration.

    What is the declaration you are using for WaitCommEvent?

--
               - Nicholas Paldino [.NET MVP]


Quote:
> Could someone please help. I'm getting a ERROR_INVALID_PARAMETER error
from
> GetLastError
> after calling WaitCommEvent the sencond time.

> I have no idea what causes this error.

> Francois



Tue, 14 Dec 2004 00:33:22 GMT  
 WaitCommEvent ERROR_INVALID_PARAMETER
I'm trying to build a protocol between a C# server and a dumb
client (terminal). One of the attributes of the protocol will be that it
sends busy packets to the client while processing large requests.

This obviously requires Threads. I've tried using the MSComm
ActiveX for Serial Port access but it is noy very compatible with
the whole thread thing. So I've turned to LoMaN's Serial Stream.

I'm now trying to implement WaitCommEvent in LoMaN's Serial
Stream. WaitCommEvent is a Win32 API call that tells u when
CommEvent occures. This is nicely explained in the MSDN article
"Serial Communication in Win32". It seems to work nicely in VC++
but I'm having a very hard time implementing it in C#.

Regards
Francois



Quote:
> Francois,

>     You should NOT be using GetLastError in your code.  The reason for
this
> is that the .NET runtime will rely on Win32 API function calls that might
> set this.  What you want to do is use the static GetLastWin32Error method
on
> the Marshal class, and make sure that the SetLastError flag in the
DllImport
> attribute for your declaration.

>     What is the declaration you are using for WaitCommEvent?

> --
>                - Nicholas Paldino [.NET MVP]



> > Could someone please help. I'm getting a ERROR_INVALID_PARAMETER error
> from
> > GetLastError
> > after calling WaitCommEvent the sencond time.

> > I have no idea what causes this error.

> > Francois



Tue, 14 Dec 2004 01:13:27 GMT  
 WaitCommEvent ERROR_INVALID_PARAMETER
Francois,

    I know what WaitCommEvent is, but the problem you are having is probably
related to the declaration of the function that you have.  What is the
declaration?

--
               - Nicholas Paldino [.NET MVP]


Quote:
> I'm trying to build a protocol between a C# server and a dumb
> client (terminal). One of the attributes of the protocol will be that it
> sends busy packets to the client while processing large requests.

> This obviously requires Threads. I've tried using the MSComm
> ActiveX for Serial Port access but it is noy very compatible with
> the whole thread thing. So I've turned to LoMaN's Serial Stream.

> I'm now trying to implement WaitCommEvent in LoMaN's Serial
> Stream. WaitCommEvent is a Win32 API call that tells u when
> CommEvent occures. This is nicely explained in the MSDN article
> "Serial Communication in Win32". It seems to work nicely in VC++
> but I'm having a very hard time implementing it in C#.

> Regards
> Francois


wrote

> > Francois,

> >     You should NOT be using GetLastError in your code.  The reason for
> this
> > is that the .NET runtime will rely on Win32 API function calls that
might
> > set this.  What you want to do is use the static GetLastWin32Error
method
> on
> > the Marshal class, and make sure that the SetLastError flag in the
> DllImport
> > attribute for your declaration.

> >     What is the declaration you are using for WaitCommEvent?

> > --
> >                - Nicholas Paldino [.NET MVP]



> > > Could someone please help. I'm getting a ERROR_INVALID_PARAMETER error
> > from
> > > GetLastError
> > > after calling WaitCommEvent the sencond time.

> > > I have no idea what causes this error.

> > > Francois



Tue, 14 Dec 2004 01:30:10 GMT  
 WaitCommEvent ERROR_INVALID_PARAMETER
My declaration and use of the function is as follow:

[DllImport("kernel32.dll", SetLastError=true)]
  static unsafe extern int GetLastError();

  [DllImport("kernel32.dll")]
   //private static extern bool WaitCommEvent(int hFile, ref int lpEvtMask,
ref NativeOverlapped lpOverlapped);
  static unsafe extern bool WaitCommEvent(int hFile, int* lpEvtMask,
NativeOverlapped* lpOverlapped);
  //private static extern bool WaitCommEvent(int hFile, ref int lpEvtMask,
ref OVERLAPPED lpOverlapped);

  public void myListener()
  {
   unsafe
   {
    //int lpEvtMask = EV_BREAK | EV_CTS   | EV_DSR | EV_ERR | EV_RING |
EV_RLSD | EV_RXCHAR | EV_RXFLAG | EV_TXEMPTY ;
    int lpEvtMask = EV_RXCHAR;

    NativeOverlapped o = new NativeOverlapped();
    bool fSucces = false;
    bool bReply = false;

    uint iLastError = 0;
    int iCount=0;

    fixed(int* pm_hFile = &m_hFile) //, uint iLastError = 0,
NativeOverlapped o = new NativeOverlapped(), bool fSucces = false)
    {
     fSucces = SetCommMask(*pm_hFile, lpEvtMask);
     if (!fSucces) throw new Exception("SetCommMask Failed");

     for(;;iCount++)
     {

      //o = new NativeOverlapped();
      iLastError = (uint) GetLastError();
      bReply = WaitCommEvent(*pm_hFile, &lpEvtMask, &o);

      if (bReply)
      {
       if (OnComm != null)
       {
        OnComm(this, EventArgs.Empty);
       }
      }
      else
      {
       //iLastError = 997;
       iLastError = (uint) GetLastError();

       //if ((997 == 997))// ERROR_IO_PENDING))// || (iLastError ==
ERROR_INVALID_PARAMETER))
       if ((iLastError == 997))// ERROR_IO_PENDING))// || (iLastError ==
ERROR_INVALID_PARAMETER))
       {
        Console.WriteLine("Just Some More Wait " + iCount);
       }
       else
       {
        Console.WriteLine(iLastError.ToString() + " != " +
ERROR_IO_PENDING.ToString());// + " | " +
ERROR_INVALID_PARAMETER.ToString());
        //throw new Exception("Unexpected Error Found");
       }
      }
     }
    } //fixed
   } //Unsafe
  } //myListener



Quote:
> Francois,

>     I know what WaitCommEvent is, but the problem you are having is
probably
> related to the declaration of the function that you have.  What is the
> declaration?

> --
>                - Nicholas Paldino [.NET MVP]



> > I'm trying to build a protocol between a C# server and a dumb
> > client (terminal). One of the attributes of the protocol will be that it
> > sends busy packets to the client while processing large requests.

> > This obviously requires Threads. I've tried using the MSComm
> > ActiveX for Serial Port access but it is noy very compatible with
> > the whole thread thing. So I've turned to LoMaN's Serial Stream.

> > I'm now trying to implement WaitCommEvent in LoMaN's Serial
> > Stream. WaitCommEvent is a Win32 API call that tells u when
> > CommEvent occures. This is nicely explained in the MSDN article
> > "Serial Communication in Win32". It seems to work nicely in VC++
> > but I'm having a very hard time implementing it in C#.

> > Regards
> > Francois


> wrote

> > > Francois,

> > >     You should NOT be using GetLastError in your code.  The reason for
> > this
> > > is that the .NET runtime will rely on Win32 API function calls that
> might
> > > set this.  What you want to do is use the static GetLastWin32Error
> method
> > on
> > > the Marshal class, and make sure that the SetLastError flag in the
> > DllImport
> > > attribute for your declaration.

> > >     What is the declaration you are using for WaitCommEvent?

> > > --
> > >                - Nicholas Paldino [.NET MVP]



> > > > Could someone please help. I'm getting a ERROR_INVALID_PARAMETER
error
> > > from
> > > > GetLastError
> > > > after calling WaitCommEvent the sencond time.

> > > > I have no idea what causes this error.

> > > > Francois



Tue, 14 Dec 2004 01:41:36 GMT  
 WaitCommEvent ERROR_INVALID_PARAMETER
I'm getting a ERROR_INVALID_PARAMETER error from GetLastError
after calling WaitCommEvent the sencond time.

My declaration and use of the function is as follow:

[DllImport("kernel32.dll", SetLastError=true)]
  static unsafe extern int GetLastError();

  [DllImport("kernel32.dll")]
   //private static extern bool WaitCommEvent(int hFile, ref int lpEvtMask,
ref NativeOverlapped lpOverlapped);
  static unsafe extern bool WaitCommEvent(int hFile, int* lpEvtMask,
NativeOverlapped* lpOverlapped);
  //private static extern bool WaitCommEvent(int hFile, ref int lpEvtMask,
ref OVERLAPPED lpOverlapped);

  public void myListener()
  {
   unsafe
   {
    //int lpEvtMask = EV_BREAK | EV_CTS   | EV_DSR | EV_ERR | EV_RING |
EV_RLSD | EV_RXCHAR | EV_RXFLAG | EV_TXEMPTY ;
    int lpEvtMask = EV_RXCHAR;

    NativeOverlapped o = new NativeOverlapped();
    bool fSucces = false;
    bool bReply = false;

    uint iLastError = 0;
    int iCount=0;

    fixed(int* pm_hFile = &m_hFile) //, uint iLastError = 0,
NativeOverlapped o = new NativeOverlapped(), bool fSucces = false)
    {
     fSucces = SetCommMask(*pm_hFile, lpEvtMask);
     if (!fSucces) throw new Exception("SetCommMask Failed");

     for(;;iCount++)
     {

      //o = new NativeOverlapped();
      iLastError = (uint) GetLastError();
      bReply = WaitCommEvent(*pm_hFile, &lpEvtMask, &o);

      if (bReply)
      {
       if (OnComm != null)
       {
        OnComm(this, EventArgs.Empty);
       }
      }
      else
      {
       //iLastError = 997;
       iLastError = (uint) GetLastError();

       //if ((997 == 997))// ERROR_IO_PENDING))// || (iLastError ==
ERROR_INVALID_PARAMETER))
       if ((iLastError == 997))// ERROR_IO_PENDING))// || (iLastError ==
ERROR_INVALID_PARAMETER))
       {
        Console.WriteLine("Just Some More Wait " + iCount);
       }
       else
       {
        Console.WriteLine(iLastError.ToString() + " != " +
ERROR_IO_PENDING.ToString());// + " | " +
ERROR_INVALID_PARAMETER.ToString());
        //throw new Exception("Unexpected Error Found");
       }
      }
     }
    } //fixed
   } //Unsafe
  } //myListener

Any help or hints will be greatly appreciated

Regards
Francois



Tue, 14 Dec 2004 23:27:37 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. CreateFile returns Error_invalid_parameter - the parameter is incorrect.

2. ERROR_INVALID_PARAMETER

3. Monitoring WaitCommEvent

4. How to break the WaitCommEvent -function?

5. WaitCommEvent Serial Port

6. Problem with WaitCommEvent in WindowsNT...

7. Exit Thread on WaitCommEvent

8. WaitCommEvent() Win9x :-) WinNT :-(

9. Any one used WaitCommEvent Function?

10. WaitCommEvent question

11. Problem with "WaitCommEvent" function

12. WriteFile,WaitCommEvent,ReadFile problem.

 

 
Powered by phpBB® Forum Software