|
Hello everyone,
I want to know the status of a completion port before dequeuing a io request, Can I determine how many pending I/O requests in a completion port before calling GetQueuedCompletionStatus()?
Thanks.
Kerry Chou from STU
|
|
|
|
|
ok guys, this is driving me crazy:
#include "comdef.h"<br />
<br />
HRESULT fn(VARIANT v)<br />
{<br />
HRESULT hr = VariantChangeType(&v, &v, 0, VT_BSTR);<br />
return hr;<br />
}<br />
int main(int argc, char* argv[])<br />
{<br />
variant_t v1(L"1"); <br />
variant_t v2(L"2");<br />
fn(v1);<br />
fn(v2);
return 0;<br />
}
now, when fn(v2); is called, the value of v1 is changed to "2".
i believe that i'm doing something wrong, but i can't see what.
|
|
|
|
|
Perhaps pass v to fn() by reference?
i.e. HRESULT fn(VARIANT& v);
"You can stand all night at a redlight anywhere in town, hailing Marys left and right but none of them slow down. I've seen the best of men go past. I don't wanna be the last..."
|
|
|
|
|
That would work correctly, and i would do that if it was a "real" code.
but the code in the snippet is perfectly legal c++ (or at least i think so)
so i'm not sure what's the reason for such behavior
|
|
|
|
|
You are right. Do I feel like an idiot or what?
However, the reason for this strange behaviour (I think) is that
the BSTR is deallocated within ChangeType and then reallocated.
(It probably doesn't check whether it is changing into the same type, i.e. BSTR->BSTR)
This means that the new pointer is lost since it was assigned to a temp. object.
The _variant_t contains the old pointer that now points to deallocated memory.
I.e. the _variant_t BSTR pointer is dangling after the fn() call.
Then the ghost value is a result of the memory allocation implementation.
"You can stand all night at a redlight anywhere in town, hailing Marys left and right but none of them slow down. I've seen the best of men go past. I don't wanna be the last..."
|
|
|
|
|
yes, i came to the same conclusion during the lunch
thanks for help, anyway
|
|
|
|
|
Hi,
Anyone have any suggestions on how to solve the following prob?
The interface of my app is built out of several different child windows and one of those contains a small coloured square. When you move the mouse over it some text is displayed.
The problem is that when you move the mouse out of the square AND out of the child window too fast the text doesn't disappear, because the WM_MOUSEMOVE message doesn't fire fast enough.
I suppose I could solve it by letting the rollover trigger a timer loop that keeps checking whether the mouse is still over the square, but that seems like a difficult solution.
Perhaps there is a more graceful solution; like an event that fires when the mouse leaves the child window or something?
Thanks,
ren
|
|
|
|
|
perhaps WM_MOUSELEAVE could do this
|
|
|
|
|
Perhaps calling TrackMouseEvent helps. Then you're notified about the mouse entering or leaving your window, and you're able to react properly on WM_MOUSELEAVE.
|
|
|
|
|
If you want to do it using a timer, here is an example.
// Header
UINT m_uiTimerId;
// CPP file
m_uiTimerId = 100; // Or whatever value you want
// In your message handler
case WM_MOUSEMOVE :
{
if(!bHovering)
{
SetTimer(hThisWnd, m_uiTimerId, 100, NULL);
bHovering = true;
}
}
return 0;
case WM_TIMER : // Timer
{
POINT obPoint;
memset(&obPoint, 0, sizeof(POINT));
GetCursorPos(&obPoint);
ScreenToClient(hThisWnd, &obPoint);
RECT obRect;
GetClientRect(hThisWnd, &obRect);
if(!PtInRect(&obRect, obPoint)) // Is the mouse still over our control
{
bHovering = false;
KillTimer(hThisWnd, m_uiTimerId);
obRect.bottom += 10;
InvalidateRect(hThisWnd, &obRect, TRUE);
}
}
break; // Let this fall through
regards,
Dark Angel
www.sfxangel.com
|
|
|
|
|
Thanks. This was exactly the type of solution I was looking for.
Just a note though:
I had to use _TrackMouseEvent instead of TrackMouseEvent. Apparently the regular TrackMouseEvent is not supported on all Windows platforms (mine is XP and the compiler threw an 'undeclared identifier'). But you can still use _TrackMouseEvent; it just calls TrackMouseEvent if it is defined and emulates it if not.
Thanks again.
|
|
|
|
|
(1) What would be the today’s technology for small desktop database applications?
I still use MFC and ODBC with static linking and dbf files for data storage.
By the way: it’s fantastic what you can make with the new DataSet and the WriteXml() and ReadXml() methods, but I can't afford to rely on the .NET Framework.
A nice standalone MFC CDataSet with Read\WriteXml() methods would be the perfect solution, but (2) does such I nice thing exist? (or could someone here write an article about such a goodie? )
_____________
stefan bornuz
|
|
|
|
|
I'll only give you my answer to question #1...
I would choose an Access (mdb) or MSDE database and access it using the ATL OLEDB consumer templates.
Very fast and pretty easy to use.
"You can stand all night at a redlight anywhere in town, hailing Marys left and right but none of them slow down. I've seen the best of men go past. I don't wanna be the last..."
|
|
|
|
|
...using the ATL OLEDB consumer templates.
Does this mean that I'll have to manage versions of mdac_typ on client's machine?
To avoid this, I didn't switch to ADO....
Anyway, thanks for answering to question #1! I hope there will be other answers too! I'm curious what's considered to by the right way in this field.
cheers,
_____________
stefan bornuz
|
|
|
|
|
What's wrong with the 'printing pictures without MFC' article ? How are you stuck ? What is happening ?
Christian
No offense, but I don't really want to encourage the creation of another VB developer.
- Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael
P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not
as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
wow, that was a really fast answer.
I have tried the article "How to print a bmp.." but i find the code very confusing.
CDC memDC;
CClientDC dc(this);
int bmpWidth = 1600;
int bmpHeight = 500;
memDC.CreateCompatibleDC( &dc );
CBitmap * bitmap = new CBitmap();
bitmap->CreateCompatibleBitmap(&dc,bmpWidth, bmpHeight);
CBitmap * pOldBitmap = (CBitmap *) memDC.SelectObject( bitmap );
comment: i want to load a resource bmp.
comment: what does thi mean, I don´t knoe how to draw...
I just want the part that prints the actual picture, i already can print text, lines etc. dcPrint.TextOut(...) ...
I think the problem here is the functions StretchBlt and BitBlt and how they works. I´m realy greatful for help on this
I´m a beginner, but I`m trying...
|
|
|
|
|
*Tom* wrote:
comment: i want to load a resource bmp.
OK, so you need to load a resource bitmap instead, ::LoadImage will do that for you, I believe.
*Tom* wrote:
comment: what does thi mean, I don´t knoe how to draw...
You need to use StretchBlt, BitBlt will leave the image too small. You also need to SetStretchBltMode to COLORONCOLOR. I may have the funtion name wrong, but that is the value you need to stop the image looking awful when stretched.
*Tom* wrote:
I think the problem here is the functions StretchBlt and BitBlt and how they works.
Sounds like you're half way there. StretchBlt stretches an image from one DC to another, and BitBlt draws it without stretching. You need to create a DC, select the image into it after loading, then use StretchBlt to draw it onto the print DC. Then you need to unselect the image ( when you select an image into a DC, the old image is returned, that's what the CBitmap * pOldBitmap line is above. You select that one back into the DC, and so free your other one, which needs deleting ).
Christian
No offense, but I don't really want to encourage the creation of another VB developer.
- Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael
P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not
as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Thanks that really explained a lot how it works , I think the problem as you say is the coping between the dc´s, here is my code that I use now:
CBitmap bitmapResource;
bitmapResource.LoadBitmap(IDB_PRINTLOGGA);
BITMAP bmResource;
bitmapResource.GetBitmap(&bmResource);
CClientDC dc(this);
CDC memClientDC;
memClientDC.CreateCompatibleDC(&dc);
CBitmap *pOldBitmapResource = (CBitmap *)memClientDC.SelectObjectbitmapResource);
if (pOldBitmapResource == NULL)
{
memClientDC.DeleteDC();
return ;
}
CPrintDialog dlgPrint(FALSE,PD_ALLPAGES,this);
if(dlgPrint.DoModal()==IDOK)
{
CDC dcPrint;
dcPrint.CreateCompatibleDC(&memClientDC);
dcPrint.Attach(dlgPrint.GetPrinterDC());
DOCINFO myPrintJob;
myPrintJob.cbSize = sizeof(myPrintJob);
myPrintJob.lpszDocName = "myPrintJob";
myPrintJob.lpszOutput = NULL;
myPrintJob.lpszDatatype = NULL;
myPrintJob.fwType = NULL;
if(dcPrint.StartDoc(&myPrintJob)>=0)
{
dcPrint.StartPage();
dcPrint.SelectObject(&ArialFontHeader);
dcPrint.TextOut(0,0,"Membercard");
...more printing text code...
dcPrint.BitBlt(1600,5500,1500,1500, &memClientDC, 0,0, SRCCOPY);
dcPrint.EndPage();
dcPrint.EndDoc();
}
dcPrint.DeleteDC();
}
feel free to comment, note this code does not print the picture as I want it
|
|
|
|
|
*Tom* wrote:
CBitmap *pOldBitmapResource = (CBitmap *)memClientDC.SelectObjectbitmapResource);
I presume this usually ends SelectOBject(&bitmapResource) ?
*Tom* wrote:
if (pOldBitmapResource == NULL){ memClientDC.DeleteDC(); return ;}
I reckon this will almost always fail, I thought you got NULL back in the first instance on a new DC. Have you traced it ?
*Tom* wrote:
dcPrint.CreateCompatibleDC(&memClientDC); dcPrint.Attach(dlgPrint.GetPrinterDC());
I think the first line is redundant, the Attach will delete the Created DC internally.
*Tom* wrote:
dcPrint.BitBlt(1600,5500,1500,1500, &memClientDC, 0,0, SRCCOPY);
This should print a postage stamp sized bitmap somewhere on your page.
I have not written printing code for a long time, so I can't comment directly. I'd be inclined to trace into this and see where it goes and what the values of various things are on the way through.
Christian
No offense, but I don't really want to encourage the creation of another VB developer.
- Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael
P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not
as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
*Tom* wrote:
I think the problem here is the functions StretchBlt and BitBlt and how they works.
You have to note that StretchBlt and BitBlt are not supported by all device contexts. I think printer DCs will not support them.
You may want to use the GetDeviceCaps member function of the CDC class with the parameter RASTERCAPS to determine if your printer DC supports them. See MSDN Library for details.
|
|
|
|
|
CodeBrain wrote:
You have to note that StretchBlt and BitBlt are not supported by all device contexts
I have look in the MSDN but I´m just confused, isn´t there a easy way to do this.
|
|
|
|
|
CodeBrain wrote:
You have to note that StretchBlt and BitBlt are not supported by all device contexts
so if the device not support StretchBlt and BitBlt, then there is impossible to print a bmp picture?
|
|
|
|
|
There is a way!
Take a look at my article PrintingTricksAndTips.asp[^]in the printing section. You need to convert your bitmap to a DIB and use StretchDIBBits() to plot it on the output device.
Most of the code shown in the article should work for non MFC code as well.
Roger Allen
Sonork 100.10016
This is a multiple choice question, choose wisely
Why did the hedgehog cross the road?
A: To show he had guts?
B: To see his flat mate?
|
|
|
|
|
Thanks Roger for the comment. But I´m starting to realize that this forum is not for a beginner like me, and with beginner I mean really a beginner . I have read your code and a have a question about the first row in "how to implement..." and that is: What is iImage? , i´m using a bitmap as a resource or alternative from a file. I attach my code if you have the time to help me how to implement the functions so it will work for me.
-Tom
void CPrint::OnClickPrint()
{
UpdateData(TRUE);
CBitmap bitmapResource;
bitmapResource.LoadBitmap(IDB_MYBMP);
BITMAP bmResource;
bitmapResource.GetBitmap(&bmResource);
CDC memDC;
CClientDC dc(this);
memDC.CreateCompatibleDC(&dc);
CBitmap * pOldBitmap = (CBitmap *) memDC.SelectObject( bitmapResource );
CPrintDialog dlgPrint(FALSE,PD_ALLPAGES,this);
if(dlgPrint.DoModal()==IDOK)
{
CDC dcPrint;
dcPrint.Attach(dlgPrint.GetPrinterDC());
DOCINFO myPrintJob;
myPrintJob.cbSize = sizeof(myPrintJob);
myPrintJob.lpszDocName = "myPrintJob";
myPrintJob.lpszOutput = NULL;
myPrintJob.lpszDatatype = NULL;
myPrintJob.fwType = NULL;
if(dcPrint.StartDoc(&myPrintJob)>=0)
{
dcPrint.StartPage();
dcPrint.SelectObject(&ArialFontHeader);
dcPrint.TextOut(...);
dcPrint.SelectObject(&ArialFont);
dcPrint.SelectObject(&ArialFontHeaderCard);
dcPrint.TextOut(...);
dcPrint.SelectObject(&ArialFont);
dcPrint.EndPage();
dcPrint.EndDoc();
}
dcPrint.DeleteDC();
}
}
|
|
|
|
|
someone knows how to convert from a bitmap to a DIB and use StretchDIBBits() DIB´s to use with the article PrintingTricksAndTips in the printing section.
- Tom
|
|
|
|
|