Skip to content

Commit

Permalink
Add DriverInfo fix
Browse files Browse the repository at this point in the history
Fixes: alexbrainman#25
Co-Authored-By: palevi67 <[email protected]>
  • Loading branch information
Tarasa24 and palevi67 committed Jul 29, 2024
1 parent fe46f6e commit 5e658c3
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,19 +305,14 @@ func (p *Printer) Jobs() ([]JobInfo, error) {
// DriverInfo returns information about printer p driver.
func (p *Printer) DriverInfo() (*DriverInfo, error) {
var needed uint32
b := make([]byte, 1024*10)
for {
err := GetPrinterDriver(p.h, nil, 8, &b[0], uint32(len(b)), &needed)
if err == nil {
break
}
if err != syscall.ERROR_INSUFFICIENT_BUFFER {
return nil, err
}
if needed <= uint32(len(b)) {
return nil, err
}
b = make([]byte, needed)
err := GetPrinterDriver(p.h, nil, 8, nil, needed, &needed)
if err != syscall.ERROR_INSUFFICIENT_BUFFER {
return nil, err
}
b := make([]byte, needed)
err = GetPrinterDriver(p.h, nil, 8, &b[0], needed, &needed)
if err != nil {
return nil, err
}
di := (*DRIVER_INFO_8)(unsafe.Pointer(&b[0]))
return &DriverInfo{
Expand Down

1 comment on commit 5e658c3

@davidlam-winc
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

life saver!

Please sign in to comment.