Link to home
Start Free TrialLog in
Avatar of abelblaine111
abelblaine111

asked on

Simple IO problem

I'm trying to write/read information from a file but I can't seem to get it working.  The error I get is 1784 which is ERROR_INVALID_USER_BUFFER.  Below is the code that I used to connect and write information.  The code should be easy to fix, I've seen many examples of working code, but I could really use some explanation of whats going on here, especially with buffers.  
Thanks.


void CTalkerDlg::OnConnectButton()
{
          m_hComPort = CreateFile(
          TEXT("COM1:"),              
          GENERIC_READ | GENERIC_WRITE,
          0,                              
          NULL,                                  
          CREATE_ALWAYS,
          OPEN_EXISTING,
          FILE_ATTRIBUTE_NORMAL,
          NULL                                  
          )
}


void CTalkerDlg::OnSendButton()
{
               char* lpBuf = "foo";
               DWORD dwWritten;
               WriteFile(m_hComPort, lpBuf, dwWritten, &dwWritten, NULL);
}
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of abelblaine111
abelblaine111

ASKER

Thanks jkr.  That was the problem.  But what exactly is a buffer?  Is it just any variable? does it have to be a char?  Like I said before my problem is more with conception.  What is a buffer?
Thanks
Abe
Thanks jkr.  That was the problem.  But what exactly is a buffer?  Is it just any variable? does it have to be a char?  Like I said before my problem is more with conception.  What is a buffer?
Thanks
Abe
>>But what exactly is a buffer?  Is it just any variable? does it have to be a char?

It sort of can be a pointer to any variable type, depending on what you want to write. If you e.g. wanted to send an 'int', you would

             int nBuf = 1234;
             DWORD dwWritten;
             DWORD dwBufSize = sizeof ( int);
             WriteFile(m_hComPort, ( LPVOID) &nBuf, dwBufSize, &dwWritten, NULL);
Thats what I'm looking for.  Thanks jkr.