Jump to content
Sign in to follow this  
Robert Gilland

GetDeviceCaps freezes everything

Recommended Posts

I borrowed the below function from jclPrint.pas using Delphi 10.4.2 

 

When function is called the entire process fails.

What could be wrong.

 

function GetPrinterResolution: TPoint;
begin
  Result.X := GetDeviceCaps(Printer.Handle, LogPixelsX);
  Result.Y := GetDeviceCaps(Printer.Handle, LogPixelsY);
end;

Share this post


Link to post

If you put a breakpoint on the first GetDeviceCaps line, do you reach it when running under the debugger? If so, does Printer.Handle have a reasonable value? Are you dealing with a network printer here that may be offline?

 

So many questions, so little data...

Share this post


Link to post

By sheer exasperation, I removed the conditionals for FASTMM4 LogMemoryLeakDetailToFile and FullDebugMode.

And then GetDeviceCaps worked, no idea why.

Another day of banging my head against the wall ends miraculously, Thank God.

 

 

Share this post


Link to post
1 minute ago, PeterBelow said:

If you put a breakpoint on the first GetDeviceCaps line, do you reach it when running under the debugger? If so, does Printer.Handle have a reasonable value? Are you dealing with a network printer here that may be offline?

 

So many questions, so little data...

Yes I did that.

Share this post


Link to post
On 12/9/2024 at 9:55 PM, Robert Gilland said:

And then GetDeviceCaps worked

Probably the printer was offline or unreachable before; and then it was reachable.

 

This happens every day here when trying to print from many, even well known applications; they take forever to time out if the default printer wasn't turned on.

 

You could try using a worker thread for printing, then your application doesn't freeze and you have some control over what happens

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×