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::OnConnectButto n()
{
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);
}
Thanks.
void CTalkerDlg::OnConnectButto
{
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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);
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);
ASKER
Thats what I'm looking for. Thanks jkr.
ASKER
Thanks
Abe