|
Hi
I Wrote a program to Communicate with a Serial Port in MFC.The problem is if i use WriteFile and ReadFile immediately i get the correct data.But if i Start a thread and use WaitCommEvent then the Program gets stuck up in WriteFile.
I hav filled the DCB structure too.
what could be the problem with WriteFile??
PS:I am not using Overlapped I/O
Any Links Would do Fine.
"Every morning I go through Forbes list of 40 richest people in the world. If my name is not in there, I go to work..!!!"
|
|
|
|
|
I think you have to post the relevant code.
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.
|
|
|
|
|
QuickDeveloper wrote: if i Start a thread and use WaitCommEvent then the Program gets stuck up in WriteFile.....I am not using Overlapped I/O
If you're not using overlapped I/O, you can only issue one request at any given time to the driver. If you issue another it will block waiting for the previously issued request, which is exactly what happens in your case: ::WaitCommEvent() is waiting for something to happen before returning while blocking the ::WriteFile() call.
If you're writing an application that is supposed to issue both read and write requests, you should only consider the overlapped alternative.
Have a look at an example on overlapped I/O here[^].
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Thanks Roger ...i am using Overlapped I/O and it's Working Fine.
"Every morning I go through Forbes list of 40 richest people in the world. If my name is not in there, I go to work..!!!"
|
|
|
|
|
I want to get a particular testsuite for execution of cppunit testcases in vc++
|
|
|
|
|
|
Hi,
I am new to vc++.
I am trying to creat file using the following code.but it is not creating the file.INVALID_HANDLE_VALUE is returned. what may be the reason for the failure.
hFile = CreateFile(m_storagePath,GENERIC_REA|ENERIC_WRITE, FILE_SHARE_READ, NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
if (hFile == INVALID_HANDLE_VALUE)
{
AfxMessageBox( "File cant be created ");
//return 0;
}
Help Ever Hurt Never
|
|
|
|
|
Call GetLastError() to get the error code, when CreateFile() returns INVALID_HANDLE_VALUE.
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
|
|
|
|
|
thanks for your reply.
i tried by including
DWORD dw = GetLastError();
after creating the file . and its returning 0X0000.
and dont know what the return value indicates?
please guide me.
Help Ever Hurt Never
|
|
|
|
|
Shouldn't happen. Does your code look something like this?
if (hFile == INVALID_HANDLE_VALUE)
{
DWORD dw = GetLastError();
AfxMessageBox( "File cant be created ");
}
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
|
|
|
|
|
|
Could be a lot of things. What is in m_ storagePath ? Does the file exist? Do you have read and write access to it? Does some other process have it open and it's only shared for reading?
|
|
|
|
|
you can get the error string by using FormatMessage() . Just change the code to as shown below. This will display the error string corresponding to that of error code.
hFile = CreateFile( m_storagePath,<br />
GENERIC_READ|GENERIC_WRITE, <br />
FILE_SHARE_READ,<br />
NULL,<br />
OPEN_ALWAYS,<br />
FILE_ATTRIBUTE_NORMAL,<br />
0);<br />
<br />
<br />
if (hFile == INVALID_HANDLE_VALUE) <br />
{ <br />
LPVOID lpMsgBuf;<br />
FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | <br />
FORMAT_MESSAGE_FROM_SYSTEM | <br />
FORMAT_MESSAGE_IGNORE_INSERTS,<br />
NULL,<br />
GetLastError(),<br />
MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ), <br />
( LPTSTR ) &lpMsgBuf,<br />
0,<br />
NULL );<br />
<br />
cout << endl << (LPCTSTR)lpMsgBuf << endl;<br />
<br />
LocalFree( lpMsgBuf );<br />
}
Regards,
Vijay.
God may not give us what we 'want', but he surely gives us what we 'need'.
|
|
|
|
|
How can we change the size of the splitter bar in a splitter window?
- NS -
|
|
|
|
|
Derive a custom class from CSplitterWnd class. In the constructor of derived class change the value of m_cxSplitter and m_cySplitter. Simply doing this will slove your problem and use the derived class instance
Do your Duty and Don't expect the Result
|
|
|
|
|
Thanks a lot...
I found some other useful variables too...
- NS -
|
|
|
|
|
NS17 wrote: I found some other useful variables too
Just curious...
|
|
|
|
|
I use these (where splitterwidth is the size of the splitter I want and borderwidth is the size
of the 3-D border around the views:
m_cxSplitter = m_cySplitter = splitterwidth + borderwidth * 2;
m_cxBorderShare = m_cyBorderShare = 0
m_cxSplitterGap = m_cySplitterGap = splitterwidth + borderwidth * 2;
m_cxBorder = m_cyBorder = borderwidth;
I also added customizable colors to all individual borders and the splitter which required a
CSplitterWnd::OnDrawSplitter() override.
I almost wrote an article for it (it all started in response to a CP question) but I noticed
hundreds of articles were already there LOL.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
sir,
I am working on vc++ project and it is based on document view architecture and I am trying to embed an active-x component into my project.
why it takes more time, when i try to create a component on the display document for the first time. The same component when i try to create subsequent time it takes less time. could you please throw some light on it.
Thanks & Regards,
Praveen A.
praveena@navayuga.co.in
pv_pravin@yahoo.co.in
|
|
|
|
|
To hide a dos windwow,
I placed the following line in the top of progam under all include files and the dos window will not be appeared when run the program.
#pragma comment(linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"")
But,
I take the exe and add it to the setup file(build in .net) the dos window will appear.what a pbm.how to hide the dos window.
|
|
|
|
|
I can help u regarding this. But make u'r doubt more specific.
Come online at:-
jubinc@skype
|
|
|
|
|
Hello ,
Can anyone help with the declaration of arrays on the .NET 2.0 platform ? I get an error "subscript requires array or pointer type . Codes listed below
public: System::Void convertStringToBinary(String ^myString)
{
binaryVal = "";
__wchar_t characterArray gcnew[];
characterArray = new __wchar_t gcnew[myString->Length];
myString->CopyTo(0, characterArray, 0, myString->Length);
for(unsigned long int i=0; i<characterarray->Length; i++)
{
binaryVal = String::Concat(binaryVal, characterArray[i]>=128 ? "1":"0");
characterArray[i] %= 128;
D
|
|
|
|
|
|
Maybe something like:
array<__wchar_t> ^characterArray = gcnew array<__wchar_t>(myString->Length);
And yes, this should be posted on the C++/CLI board
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Thanks it worked
|
|
|
|