?
Solved

Simple IO problem

Posted on 2003-03-12
5
Medium Priority
?
2,214 Views
Last Modified: 2013-11-20
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);
}
0
Comment
Question by:abelblaine111
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 240 total points
ID: 8121743
>>The error I get is 1784 which is ERROR_INVALID_USER_BUFFER.

The error code is correct - you are specifying an incorrect value as the 3rd parameter, which is supposed to be the length of the buffer to write. Use

void CTalkerDlg::OnSendButton()
{
              char* lpBuf = "foo";
              DWORD dwWritten;
              DWORD dwBufSize = lstrlen ( lpBuf);
              WriteFile(m_hComPort, lpBuf, dwBufSize, &dwWritten, NULL);
}


0
 

Author Comment

by:abelblaine111
ID: 8121807
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
0
 

Author Comment

by:abelblaine111
ID: 8121878
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
0
 
LVL 86

Expert Comment

by:jkr
ID: 8122065
>>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);
0
 

Author Comment

by:abelblaine111
ID: 8122713
Thats what I'm looking for.  Thanks jkr.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question