|
I am writing a class for serial port communication.
It always returns FALSE when I set commport state by calling
win32 api SetCommState.
following is some code from my class:
//code starts here
//m_hComm is an effective handle to commport
m_dcb.DCBlength= sizeof(DCB);
m_dcb.BaudRate =nBaud;
m_dcb.ByteSize = nDataBits;
m_dcb.Parity =nParity ;
m_dcb.StopBits =nStopBits;
m_dcb.fBinary=TRUE;
m_dcb.fDsrSensitivity=FALSE;
m_dcb.fParity=bParity;
m_dcb.fOutX=FALSE;
m_dcb.fInX=FALSE;
m_dcb.fNull=FALSE;
m_dcb.fAbortOnError=TRUE;
m_dcb.fOutxCtsFlow=FALSE;
m_dcb.fOutxDsrFlow=FALSE;
m_dcb.fDtrControl=DTR_CONTROL_DISABLE;
m_dcb.fDsrSensitivity=FALSE;
m_dcb.fRtsControl=RTS_CONTROL_DISABLE;
m_dcb.fOutxCtsFlow=FALSE;
m_dcb.fOutxCtsFlow=FALSE;
BOOL bRet= ::SetCommState(m_hComm, &m_dcb);
if(!bRet)
{
CloseHandle(m_hComm);
MessageBox(NULL, "Set comm state error!", NULL, MB_OK);
return FALSE;
}
//code ends here
The bRet of above is always FALSE.How I can call SetCommState Successfully?
I need your help. Thanks.
|
|
|
|
|
Shouldn't it be SetCommState, not ::SetCommState?
Cheers,
Fredrik
"Felix qui potuit rerum cognoscere causas."
|
|
|
|
|
hi,
I met a problem when I using serialize/deserialize of CObject in VC++ 6.0. Who can kindly give some help?
I serialize a object array to store them in the disk file. When I try to deserialize them back from file. I found the time spent on this would increase exponentially with the size of file. When file is 500K, it need about 1 senconds. when file is 1M, it takes about 3 second... when file is 15M, it takes several minutes. I had hoped my program could handle file of handreds megabytes. this speed is unaccept for me.
regards,
jim wang
|
|
|
|
|
Have you profiled the code to see where the bottleneck is? Glowcode www.glowcode.com[^] is good for this. VC++ also has profiling capabilities.
The exponential increase doesn't seem right. It may be a combination of reading/parsing and allocating memory. If you are using the heap and that's a performance issue then there are fast heap managers around.
But I have to wonder why you are serializing a 15M file.
I can tell you that using pugXML (here on CP) in Memory Mapped File mode I can read and parse a 10M XML file in about .5 sec on a slow old 550Mhz P3.
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
When you start a thread using AfxBeginThread() does the thread function have to be a static member? Anyone know how to start a thread function that isn't static?
Mike Ellertson
|
|
|
|
|
Mike Ellertson wrote:
does the thread function have to be a static member?
Yes. Pass a pointer to the class as an LPVOID parameter then inside the static function call whatever member function using the pointer.
John
|
|
|
|
|
Mike Ellertson wrote:
Anyone know how to start a thread function that isn't static?
Take a look at this article[^].
Who is 'General Failure'? And why is he reading my harddisk?!?
|
|
|
|
|
The m_child is derive from CWnd, but it can't get focus, the caption of this child window is always gray.
m_child.Create( NULL, "OK", WS_VISIBLE | WS_CHILD | WS_CAPTION,
rc, this, 100, NULL );
|
|
|
|
|
You need to provide more information. What class is m_Child? Where are you creating it?
If this is on a dialog, you may be missing WS_TABSTOP. If you are inheriting from CStatic
then you will also have issues, as that passed focus to its parent.
You should also look up WM_GETDLGCODE.
etc.
Iain.
|
|
|
|
|
m_Child is my custom window and it derive from CWnd, this is SDI project, m_Chils is member of my view.
|
|
|
|
|
I want to make a program that connects to a hardware circuit through either the printer port or a serial port. I am wondering how I could make my application run in the background until the circuit transmits some data through the port, upon which I should receive and manipulate it. Could you please tell me how to do it in MFC or Win32 API? Thank you very much.
Hosam Aly Mahmoud
|
|
|
|
|
I was once told that u couldnt start a thread from a class function like so:
class MyClass
{
public void ThreadFunc();
}
CreateThread(ThreadFunc,blablabla);
Ok this isnt exact but it should tell u what i mean. But if thats the case, then how did they do this in MFC. There is a class CWinThread, and u can use AfxBeginThread to start a thread like that, so apparently it is creating a thread from a class.... So can i make a class that encapsulates my thread? How?
Thanks.
Kuniva
--------------------------------------------
|
|
|
|
|
Declare ThreadFunc() as static .
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Do you know of any way to get around the static function requirement? It's kind of a pain, because now I can't access other data members that aren't static.
Mike Ellertson
|
|
|
|
|
Mike Ellertson wrote:
Do you know of any way to get around the static function requirement?
No, not for threads.
Mike Ellertson wrote:
I can't access other data members that aren't static.
The CreateThread() accepts an lParam value that is passed to the ThreadProc() function. Pass a pointer to the thread object, and then you can access the non-static members through this pointer. You can simply call a non-static function to do all the work if you want to:
class ThreadClass
{
public:
static LRESULT CALLBACK ThreadProc(LPARAM lParam)
{
ThreadClass *pThread = (ThreadClass*)lParam;
return pThread->NonStaticThreadProc();
}
LRESULT NonStaticThreadProc()
{
return 0;
}
};
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Wow.. Thank you very much
Kuniva
--------------------------------------------
|
|
|
|
|
You're welcome
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
|
void Bla(Foo foo) ->
You cannot modify the parameter foo directly, only a copy of its value will be passed.
void Bla(Foo *foo) ->
You can modify the address pointed to by foo with foo = 0x045345 or change the value with *foo = 123 .
Make sure foo does not point to a NULL reference.
void Bla(Foo& foo) ->
Value passed by reference, you can change the value simply with foo = 123
regards
Greg
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Thanx
Greg S. wrote:
You can modify the address pointed to by foo with
I tend to differ... EG
void Bla(Foo* foo)<br />
{<br />
foo->a = 99;<br />
foo = NULL;<br />
}
foo.a == 99 after method, not NULL.
Greg S. wrote:
void Bla(Foo& foo)
->
Value passed by reference, you can change the value simply with foo = 123
The compiler wont even let me define the method. Is this a C++ specific operator? BTW I'm only (allowed to) use C, not C++.
leppie::AllocCPArticle(Generic DFA State Machine for .NET);
|
|
|
|
|
|
void BlaP(Foo *foo);
void BlaR(Foo& foo);
Is the difference merely "syntax" or are references somehow better than pointers? (I mean if you are dealing with one object, not an array of course!)
<marquee behavior="alternate">Hosam Aly Mahmoud
|
|
|
|
|
References are not nessecairily better then pointers, it just depends on what you want to do! Using a pointer gives you the option to pass NULL (or use it as a default parameter)! On the other hand, when you don't want to change the contents of the object (making it constant) it's a lot easier with a reference!
A student knows little about a lot.
A professor knows a lot about little.
I know everything about nothing.
|
|
|
|
|
Thanks for your reply. I agree with you in that its use is much more obvious. Also, the ability to pass NULL in pointers would have uses somewhere.
I have heard one of my friends saying that references take two bytes in memory, whereas pointers take four. Is this true? And if it is, would this allow for faster processing?
Thank you for your time.
Hosam Aly Mahmoud
|
|
|
|
|
Hosam Aly Mahmoud wrote:
I have heard one of my friends saying that references take two bytes in memory, whereas pointers take four. Is this true?
No. References take the same amount of memory as pointers.
References are generally safer than pointers because they are gauranteed to point to something, and they are type-safe (they can't be cast to references of incompatible types).
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|