alexbrainman / printer

Windows printing
BSD 3-Clause "New" or "Revised" License
227 stars 80 forks source link

StartRawDocument: The data is invalid. #25

Open palevi67 opened 6 months ago

palevi67 commented 6 months ago

I'm getting an "The data is invalid" error when calling StartRawDocument ... this was working some weeks ago, so I think it might be caused by some OS upgrade.

¿Any idea?

I'm under W11.

alexbrainman commented 6 months ago

¿Any idea?

No idea. Sorry.

Alex

palevi67 commented 5 months ago

I have traced down the program and found the error was generated in the DriverInfo() function. I changed it to the following, and now StartRawDocument() is working again:

// DriverInfo returns information about printer p driver.
func (p *Printer) DriverInfo() (*DriverInfo, error) {
    var needed uint32
    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{
        Attributes:  di.PrinterDriverAttributes,
        Name:        windows.UTF16PtrToString(di.Name),
        DriverPath:  windows.UTF16PtrToString(di.DriverPath),
        Environment: windows.UTF16PtrToString(di.Environment),
    }, nil
}
alexbrainman commented 4 months ago

I have traced down the program and found the error was generated in the DriverInfo() function. I changed it to the following, and now StartRawDocument() is working again:

I am glad it works for you.

I still do not understand why it fixes your problem. But I don't use this code myself, so I won't spend time investigating it.

Alex