|
In non-overlapped IO each call will block the IO resource.
You will also run into problems when you try to exit from your thread because it will be stuck on WaitCommEvent.
You have a couple of choices:
1. Don't use WaitCommEvent and instead poll the IO with GetCommModemStatus.
Polling can be OK if done infrequently.
2. Use overlapped IO. A little more complicated but it won't block the IO resource.
I'd go with overlapped IO.
Col
|
|
|
|
|
Thanks a lot Colin!
I'll look into GetCommModemStatus first, that might just be what I was looking for. Although I do need need to poll about 80 times in a few seconds, it might still work reliably.
Once again, your help's greatly appriciated.
Regards,
Griffith
Everything you say will be misquoted, ripped out of context and used against you.
|
|
|
|
|
BTW,
Since you plan to poll you should do it at least double the maximum possible expected input frequency to ensure you do not miss a pulse.
Col
|
|
|
|
|
I use visual studio.net enterprise architect
I'm coding an app with MFC.
I have a problem. After including some source directory (containing *.inl) into the include path of the project properties, VS.net crash when I use project -> 'add ressource'.
Any Ideas?
Everything's beautiful if you look at it long enough...
|
|
|
|
|
why this routine stops everytime with the errorMessageBox??
thx for help.
m_Path: absolute path to the file (for example "c:\data\test.log"
void CTestDlg::OnOK()
{
this->UpdateData(true);
CString error;
CStdioFile logFile;
CFileException fileException;
if (!logFile.Open( m_Path, CFile::modeRead ),
&fileException )
{ //ERROR
error.Format( "Can't open file %s, error = %u\n",
m_Path, fileException.m_cause );
MessageBox(error,NULL,MB_OK);
}
else
{ //all okay
logFile.Close();
}
CDialog::OnOK();
}
|
|
|
|
|
what does fileException.m_cause contain?
-c
A | B - it's not a choice.
|
|
|
|
|
the errorcode...
but i think i found the problem...
its strange... 1 day searching without success
and some minutes after this post i found a wrong placed ")"
in the if-cause ...
the ")" should be after the exception-var...
|
|
|
|
|
Hello,
I have some really simple wininet code that performs and http post and closes the handles when done. I am having a problem where on app exit, I perform a final http post and close all of my handles without fail and exit my wininet function, but the app refuses to unload until after a 60 second pause. Any ideas why?
|
|
|
|
|
Is there a simple way inside the VS6 IDE to automatically change the color of code between a #if ... #endif, preferable when using #if 0 ... #endif, which effectively removes an entire section of code? Since comments between /* ... */ can be colored, can't this be done with #if too?
Thanks,
Dave
"You can say that again." -- Dept. of Redundancy Dept.
|
|
|
|
|
For this situation, you must use macro. Writing a macro to do what you want!
A. Riazi
|
|
|
|
|
Nope, there's no way to do it.
I personally avoid leaving portions of commented-out code in my source files, whether it's with /*...*/ or #if 0. If something needs to be removed, I delete it, and I rely on my version control software to let me recover it later if necessary. I just hate looking at code with old junk all over it.
Regards,
Alvaro
All you need in this life is ignorance and confidence, and then success is sure. -- Mark Twain
|
|
|
|
|
You might want to look at Visual Assist, from Whole Tomato Software
www.wholetomato.com[^]
--
Where are we going? And why am I in this handbasket?
|
|
|
|
|
I am about to write code that will perform a dynamic_cast from Base* to Derived* in a function that got the Base* from a 'this' in a constructor.
Example :
<br />
class Base;<br />
void do_stuff( Base* );<br />
<br />
class Base<br />
{<br />
public:<br />
Base( );<br />
};<br />
<br />
class Derived : public Base<br />
{<br />
public:<br />
Derived( )<br />
{<br />
do_stuff( this );<br />
}<br />
};<br />
<br />
void do_stuff( Base* pBase )<br />
{<br />
Derived* pDerived = dynamic_cast< Derived* >( pBase );<br />
if( pDerived )<br />
do_more_stuff( pDerived );<br />
}<br />
I know using an object's virtual functions within its constructor is bad, because the virtual function table is not completely built yet. I have read about dynamic_cast stating that it can convert complete objects to complete objects, is that related to the vtable?
So, can I dynamic_cast<> a 'this' in a constructor?
----------------
Blaster
Computer game programmer and part time human being
http://www.blastersoft.com
|
|
|
|
|
Sounds like a design problem.
"But that's just my opinion... I could be wrong."
-pete
"No matter where you go, there your are..." - Buckaoo Banzi
<pete>
|
|
|
|
|
You do not need cast here, or static_cast at most. As for hypothetical bad idea of using partially constructed objects in the cast - it might not work with diamond inheritance, at least not the way intended.
|
|
|
|
|
Ufff, you're entering into quicksands here... Anyway, I think your code should work. The standard says (12.7):
5 Dynamic_casts (_expr.dynamic.cast_) can be used during construction or
destruction (_class.base.init_). When a dynamic_cast is used in a con-
structor (including from the mem-initializer for a data member) or in
a destructor, or used in a function called (directly or indirectly)
from a constructor or destructor, if the operand of the dynamic_cast
refers to the object under construction or destruction, this object is
considered to be a most derived object that has the type of the con-
structor or destructor's class. If the operand of the dynamic_cast
refers to the object under construction or destruction and the static
type of the operand is not a pointer to or object of the constructor
or destructor's own class or one of its bases, the dynamic_cast
results in undefined behavior. If you read carefully, when entering into the ctor for Derived the object already behaves as a Derived with respect to dynamic_cast .
Besides, if you're writing such a mess just to avoid calling a virtual function, then you better move to virtual because similar rules apply (and the code is a little more understandable).
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I may or may not work, but I no longer care.
Like someone said, the design is bad. I changed things a bit.
Thank you all for you information.
----------------
Blaster
Computer game programmer and part time human being
http://www.blastersoft.com
|
|
|
|
|
Damn! I just realised that in my example, the call to "do_stuff" should have been in Base's constructor, not in Derived's.
I still don't care though.
----------------
Blaster
Computer game programmer and part time human being
http://www.blastersoft.com
|
|
|
|
|
At this time I have a window in which i draws and saves screen window as bmp.
But i want to draw shapes on a window that is hidden.
I am confused that with which device context i should draw.
It will be great if u guide me on this problem.
|
|
|
|
|
dont use a window device context as such
create a memdc compatible with the window dc bitmap and draw there
"even if my world is weird its my world" biz stuff about me
|
|
|
|
|
Yes u r right
but when creating memDC using CreateCompatibleDC(....
In parameters of this function device context with which drawing is done is also given.
So what device context shold be the parameter.
As
I am creating memDc in constructor of my view class
and getting devicecontect as
CDC *pDC=GetDC(); //step1/
//doing drawing with this pdc as pDC->Rectangle(....
//after this
CDC memDC;
memDC.CreateCompatibleDC(pDC);
//and then saving window image as bmp
but i am getting an empty image in bmp file.
If i use
HDC hdc=::GetDC(NULL) in place of step1
i get figures drawn but also the desktop imageis also painted.
So which device context should be used in step1.
Thanks for ur answer
|
|
|
|
|
mkashifkkj wrote:
So which device context should be used in step1.
The screen DC, GetDC(0), will do just fine.
|
|
|
|
|
I do a lot of drawing on "imaginary" surfaces.
You could always try something like this:
<br />
BITMAP bm;<br />
GetObject(hBmp, sizeof(BITMAP), &bm);<br />
<br />
BITMAPINFO bmInfo;<br />
memset(&bmInfo.bmiHeader, 0, sizeof(BITMAPINFOHEADER));<br />
bmInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);<br />
bmInfo.bmiHeader.biWidth = bm.bmWidth;<br />
bmInfo.bmiHeader.biHeight = bm.bmHeight;<br />
bmInfo.bmiHeader.biPlanes = 1;<br />
bmInfo.bmiHeader.biBitCount = 24;<br />
<br />
HDC TmpDC = CreateCompatibleDC(NULL);<br />
<br />
BYTE *pbase;<br />
HBITMAP TmpBmp = CreateDIBSection(TmpDC &bmInfo, DIB_RGB_COLORS, (void**)&pbase, 0, 0);<br />
<br />
HGDIOBJ TmpObj = SelectObject(TmpDC, TmpBmp);<br />
<br />
HDC dcBmp = CreateCompatibleDC(TmpDC);<br />
SelectObject(dcBmp, hBmp);<br />
<br />
BitBlt(TmpDC, 0, 0, bm.bmWidth, bm.bmHeight, dcBmp, 0, 0, SRCCOPY);<br />
<br />
<br />
<br />
DeleteDC(dcBmp);<br />
<br />
DeleteObject(hBmp);<br />
hBmp = TmpBmp;<br />
SelectObject(TmpDC, TmpObj);<br />
DeleteDC(TmpDC);<br />
|
|
|
|
|
If I use InsertMenu and
BOOL InsertMenu( UINT nPosition, UINT nFlags, UINT nIDNewItem = 0, LPCTSTR lpszNewItem = NULL );
and do it in a loop which sticks in an incremented integer i (5000, 5001, 5002, etc) in the nIDNewItem position, then when I address this item in the future say using RemoveMenu(), then since I didnt put in something like ID_MYITEM, but a number instead, can I just say RemoveMenu(5001, MF_BYCOMMAND) ? Even though I didnt have a value like ID_MYITEM for that menu item?
When you add menu items dynamically , does it make entries in the resource.h file temporarily, and deletes them when the program is done?
Appreciate your help,
ns
|
|
|
|
|
Those ID_MYITEM s are just mnemonics for plain numbers. I.e. if resource.h contains
#define ID_MYITEM 5000 then ID_MYITEM is replaced by 5 before before compilation; it is just convenient notation. resource.h is not changed in any manner when running the program. So to sum it up, it is OK to add items the way you are doing without resorting to any macros defined in resource.h .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|