|
A few remarks:
(1) Why are you setting to zero all the reading timeout values?
(2) In WriteFile you're not sending the carriage return (\r), since you specified only two bytes to send.
(3) You are not checking neither the ReadFile return value nor how many bytes you obtained (i.e. the iBytesReas value, of course you have to check this only when ReadFile returns a nonzero value).
Hope that helps
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
I'm not sure if "COM7:" is a valid port name. You have omitted all error checking and assume everything works perfectly.
You don't have a clue whether the could be opened or not.
You should at least verify that m_hCom doesn't equal INVALID_HANDLE_VALUE after the call to ::CreateFile() .
You have set up the timeouts so that there won't be any timeout, ::ReadFile() will return immediately with whatever is found in the FIFO, if any. In practice; your device would have to send the response before you sent the request in order for the code you've written to get the response.
Have a look at this article[^]. It will show you how to implement serial communication.
Post again if anything is unclear after reading the article.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
|
If your doing any kind of port programming then your deffinatly going to want to check out the CSerial utility class.
http://www.codeproject.com/system/serial.asp
Its without a doubt, one kick ass class library. The sample includes C++ console, and mfc samples. Check it out pronto!
|
|
|
|
|
Hello Guru's
I am writing below code for copy the content of buffer to file
CString strLine = "";
CString buffer = "";
CStdioFile fileObj,filewrite;
CString fname;
fileObj.Open(str, CFile::modeRead | CFile::shareDenyWrite);
fname = fileObj.GetFileName();
while(fileObj.ReadString(strLine))
{
fileObj.ReadString(strLine);
buffer += strLine + "\r\n";
}
fileObj.Close();
// MessageBox(buffer);
SetDlgItemText(IDC_EDIT3,buffer);
/*//////////////////////Copying file to another folder//////////////////////////*/
fileObj.Open("c:\\UserFolder\\" + fname + ".txt",CFile::modeCreate,NULL);
///////////////////////////////////////////////////
filewrite.Open(str,CFile::modeCreate|CFile::modeWrite);
strLine.Empty();
while(filewrite.ReadString(strLine))
{
filewrite.WriteString(strLine);
fname += strLine + "\r\n";
}
filewrite.Close();
MessageBox(fname);
I am understand where i am wrong .
The above code work correctly up to
CString strLine = "";
CString buffer = "";
CStdioFile fileObj,filewrite;
CString fname;
fileObj.Open(str, CFile::modeRead | CFile::shareDenyWrite);
fname = fileObj.GetFileName();
while(fileObj.ReadString(strLine))
{
fileObj.ReadString(strLine);
buffer += strLine + "\r\n";
}
fileObj.Close();
// MessageBox(buffer);
SetDlgItemText(IDC_EDIT3,buffer);
/*//////////////////////Copying file to another folder//////////////////////////*/
fileObj.Open("c:\\UserFolder\\" + fname + ".txt",CFile::modeCreate,NULL);
and i can create an 0 byte .txt file using this .But when i try to copy content on buffer to file . I am become fail I think this code of line is wrong .
filewrite.Open(str,CFile::modeCreate|CFile::modeWrite);
strLine.Empty();
while(filewrite.ReadString(strLine))
{
filewrite.WriteString(strLine);
fname += strLine + "\r\n";
}
filewrite.Close();
MessageBox(fname);
if any one in the world tell me how can we solve this problem.
Regard's
Kaushik
|
|
|
|
|
You open file on the write mode but in this loop you want to read of that?
filewrite.Open(str,CFile::modeCreate|CFile::modeWrite);
strLine.Empty();
while(filewrite.ReadString(strLine))
From the MSDN
CFile::modeRead Opens the file for reading only.
CFile::modeReadWrite Opens the file for reading and writing.
CFile::modeWrite Opens the file for writing only.
|
|
|
|
|
if i use the mode like
filewrite.Open(str,CFile::modeCreate | CFile::modeRead);
again it can not write file
Regard's
Kaushik
|
|
|
|
|
in the read write mode
filewrite.Open(str,CFile::modeReadWrite);
it will return only name of file at last.(in messageBox)
Regard's
Kaushik
|
|
|
|
|
Hi,
I think your are mistakenly using file objects.
The following seems reading from and writting to same file. and also
"filewrite" is created in write mode.
while(filewrite.ReadString(strLine))
{
filewrite.WriteString(strLine);
fname += strLine + "\r\n";
please review it.
|
|
|
|
|
I have used other databases, but not for Ms SQL server.
I think if connection and/or open SQL server databese is successful, rest should be similar to using other database.
is it correct?
Q:
how to connect and/or open SQL server databese?
any other important points?
please help with several steps if possible.
thx
|
|
|
|
|
|
it looks not too hard - similar to c++ for mysql, both use raw functions.
is there any existing MFC classes for SQL server? any samples?
thx.
|
|
|
|
|
Did you see CDatabase Class?
|
|
|
|
|
In my Dialog based app, dialog background color has been changed, but menu-bar's color is still default (button-face).
Q:
how to change menu-bar's color to dialog's color, so the GUI looks better?
|
|
|
|
|
Hello,
Anyone have ideas about invisitasking (http://www.diskeeper.com/defrag/InvisiTasking.asp) and how to do it in c++?
Is it some kind of machine learning techniques where the program study the habit of the users and then wait until a suitable time to perform a task or is it just wait for a situation when there is low CPU usage AND no input from the user AND etc..?
|
|
|
|
|
Hello All,
I have made an application in Visual C++ and at runtime it pop ups one error dialog saying that
Debug Error!!!
and saying that
DAMAGE:after normal block(#1050693) at 0x01486430
can anyone please tell me what is the error and why it shows this error???
If any one has solution regarding this please reply me.
Thanks!!!
|
|
|
|
|
Have a look at the following thread[^] I think it might help you.
Regards,
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
My Blog: ^_^
|
|
|
|
|
I have made a project in VC++ in Visual C++ 6.0 Editor and it gives following errors while debugging.
Is there any solution for this problem???
if yes then please tell me I am so much confuse about this problem
I have free up all the memory in my whole project then also this error is shown in the Output window.
Loaded 'ntdll.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\kernel32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\shlwapi.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\advapi32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\rpcrt4.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\gdi32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\user32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\msvcrt.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\shell32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\ole32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\oleaut32.dll', no matching symbolic information found.
Loaded symbols for 'C:\WINDOWS\system32\MFC42D.DLL'
Loaded symbols for 'C:\WINDOWS\system32\MSVCRTD.DLL'
Loaded 'C:\WINDOWS\system32\comctl32.dll', no matching symbolic information found.
Loaded symbols for 'C:\WINDOWS\system32\MFCO42D.DLL'
Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.2982_x-ww_ac3f9c03\comctl32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\uxtheme.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\msctf.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\asycfilt.dll', no matching symbolic information found.
Please give me reply!!!!
Thanks in advance
|
|
|
|
|
|
where is the memory leak / error in the output?
|
|
|
|
|
ohh
its not a leakage but this will happen while I am debugging my code and also while I am running my program.
This error is going to terminate my application in between the usage of the system.
So, please give me reply
|
|
|
|
|
But you started the thread as a memory leak problem.
The log you have posted doesnot give much information of your problem.
The debugging info only shows the symbol missing error, please refer Iain Clarke's description below.
If your app terminates due to huge memory usage, you have to find it out by reviewing your code (I prefer it), debug, detect using static or dynamic source code analysers like boundschecker, ....
|
|
|
|
|
Um, what memory leakage? You're just showing that Visual C++ can't find debugging symbols for system DLLs. This isn't a great shock. This just means that when you're debugging, if the call stack goes through a system DLL, you won;t know the function name.
If this is a real problem, go look at the recently posted article on setting up a symbol server (not sure if that will work with as old a compiler / debugger and 6.0. (I use 6.0, but I also don't use the symbol server)
Iain.
|
|
|
|
|
Hi,
What API should i use to Change the Desktop backgorund
VIBIN
"Fool's run away,where angle's fear to tread"
|
|
|
|
|
Do you need to IActiveDesktop::SetWallpaper ?
|
|
|
|