DeleteDC hanging

  • Thread starter Thread starter Shaun Wilde
  • Start date Start date
S

Shaun Wilde

Hi all

I am trying to print via the IRDA: port to a pentax printer - now all goes
well up until I have to delete the DC created by CreateDC call.

When I try the same operation with no interop involved ie native all is well
and there is no hanging however as soon as I call the routine from
..NET then the DeleteDC part of the call hangs. (note the hang doesn't happen
all the time its very intermittant but is about 1 in 3 calls). note only
does it
hang the process but the whole OS such that I need to reboot the device.

Anybody experienced this and can suggest a solution.

thanks

Shaun
 
Is the DC address locked/pinned? that is, are you sure the GC didn't move
it, and when you go to release it, you're actually releasing an invalid
address?

-Chris
 
Hi chris

definitely sounds plausable can you explain? how do you "lock" a DC so this
doesn't happen?

my code looks like this (print single page document in pseudocode) in fact
much like all the printing samples

extern"C" void PrintPage() // as you can see I wrapped all the printing
calls into 1 call - I did have individual pinvoke calls
{
HDC dc = ::CreateDC(...);

if (dc!=NULL)
{
if (::StartDoc(dc,...)) // DOCINFO structure as well but I can't remember
the structure and I am at home today
{
if (::StartPage(dc))
{
// do drawing to DC - bitmaps and text

// end the page
::EndPage(dc);
}
::EndDoc(dc);
}
::DeleteDC(dc);
}
}

I've also messed with SaveDC and RestoreDC which appeared to work but it was
a false (get my hopes up on friday afternoon) alarm.

should I use PrintDlg or PageSetupDlg instead to choose the printer
settings - not sure if this will have any effect on the DC returned though

shaun
 
Back
Top