digitalmars.D.learn - Windows printing
- frame (40/40) Oct 06 2021 Is there some Windows expert or someone you can tell me if I do
- Imperatorn (2/5) Oct 07 2021 Maybe I'm reading this wrong, but don't you want DM_OUT_BUFFER?
- frame (5/11) Oct 07 2021 No, please see:
- Imperatorn (3/15) Oct 07 2021 Oh, now I see. Sorry. I think that might depend on OS version
- frame (2/4) Oct 07 2021 Why? It shouldn't matter for this purpose.
- frame (9/10) Oct 11 2021 Well, I guess you are right. If I just put the
- Imperatorn (4/14) Oct 11 2021 Interesting. Have you tried any sanity checking using any other
- Imperatorn (2/5) Oct 12 2021 https://docs.microsoft.com/en-us/windows/win32/cimwin32prov/win32-printe...
- frame (7/13) Oct 12 2021 I need interoperability with the printer driver dialogs.
Is there some Windows expert or someone you can tell me if I do things wrong? I can open the printer and also print but I'm failing to restore the printer settings from a file. ```d import core.sys.windows.windows; import core.sys.windows.winspool; import std; pragma(lib, "winspool.lib"); extern (Windows) BOOL IsValidDevmodeA(PDEVMODEA pDevmode, size_t DevmodeSize); // ... string path; // contains a valid path to a previously saved printer properties struct file char* cPrinterName; // just to simplify, it comes from toStringz and contains the correct name const(ubyte)[] pDevModeInputBuf = cast(ubyte[]) read(path); // reads 1689 bytes DEVMODEA* initData = cast(DEVMODEA*) pDevModeInputBuf.ptr; HANDLE pHandle; OpenPrinterA(cPrinterName, &pHandle, null); // success, pHandle points to something // returns the bytes needed for the printer properties long docRs = DocumentPropertiesA(null, pHandle, cPrinterName, null, null, 0); // 1689 bytes, so also correct // everyting correct: // initData.dmDeviceName == cPrinterName // initData.dmSize + initData.dmDriverExtra == docRs, 1689 bytes IsValidDevmodeA(initData, docRs); // true // just to be sure SetLastError(0); // GetLastError() is 0 // and now this fails: uint flags = DM_IN_BUFFER; docRs = DocumentPropertiesA(null, pHandle, cPrinterName, null, initData, flags); // docRs is -1 // GetLastError() is 131 // 131 = ERROR_NEGATIVE_SEEK ``` Negative seek? This is file related - what's going on here?
Oct 06 2021
On Thursday, 7 October 2021 at 01:55:15 UTC, frame wrote:Is there some Windows expert or someone you can tell me if I do things wrong? [...]Maybe I'm reading this wrong, but don't you want DM_OUT_BUFFER?
Oct 07 2021
On Thursday, 7 October 2021 at 15:38:27 UTC, Imperatorn wrote:On Thursday, 7 October 2021 at 01:55:15 UTC, frame wrote:No, please see: https://docs.microsoft.com/en-us/windows/win32/printdocs/documentproperties The output of mode DM_OUT_BUFFER is what I am tyring to import again.Is there some Windows expert or someone you can tell me if I do things wrong? [...]Maybe I'm reading this wrong, but don't you want DM_OUT_BUFFER?
Oct 07 2021
On Thursday, 7 October 2021 at 17:13:45 UTC, frame wrote:On Thursday, 7 October 2021 at 15:38:27 UTC, Imperatorn wrote:Oh, now I see. Sorry. I think that might depend on OS version iirc. Sidenote: shouldn't you use the unicode variant? 🤔On Thursday, 7 October 2021 at 01:55:15 UTC, frame wrote:No, please see: https://docs.microsoft.com/en-us/windows/win32/printdocs/documentproperties The output of mode DM_OUT_BUFFER is what I am tyring to import again.Is there some Windows expert or someone you can tell me if I do things wrong? [...]Maybe I'm reading this wrong, but don't you want DM_OUT_BUFFER?
Oct 07 2021
On Thursday, 7 October 2021 at 18:00:17 UTC, Imperatorn wrote:Oh, now I see. Sorry. I think that might depend on OS version iirc. Sidenote: shouldn't you use the unicode variant? 🤔Why? It shouldn't matter for this purpose.
Oct 07 2021
On Thursday, 7 October 2021 at 18:00:17 UTC, Imperatorn wrote:I think that might depend on OS version iirc.Well, I guess you are right. If I just put the DocumentPropertiesA() call in a loop, it locks in immediately with 0 or between 60 - 400 failed attempts, depending on the printer driver. Very weird behavior but It cannot caused by my program - the input data in memory is constant and not corrupted. Also interesting the amount of failed attempts stays exactly the same or just moves a bit but is never really random.
Oct 11 2021
On Monday, 11 October 2021 at 17:59:39 UTC, frame wrote:On Thursday, 7 October 2021 at 18:00:17 UTC, Imperatorn wrote:Interesting. Have you tried any sanity checking using any other language or using some existing code? Like, maybe you can use wmi for this? idkI think that might depend on OS version iirc.Well, I guess you are right. If I just put the DocumentPropertiesA() call in a loop, it locks in immediately with 0 or between 60 - 400 failed attempts, depending on the printer driver. Very weird behavior but It cannot caused by my program - the input data in memory is constant and not corrupted. Also interesting the amount of failed attempts stays exactly the same or just moves a bit but is never really random.
Oct 11 2021
On Thursday, 7 October 2021 at 01:55:15 UTC, frame wrote:Is there some Windows expert or someone you can tell me if I do things wrong? [...]https://docs.microsoft.com/en-us/windows/win32/cimwin32prov/win32-printerconfiguration
Oct 12 2021
On Tuesday, 12 October 2021 at 17:36:06 UTC, Imperatorn wrote:On Thursday, 7 October 2021 at 01:55:15 UTC, frame wrote:I need interoperability with the printer driver dialogs. I had a look on C++ examples but don't see huge differences. It should just work. I assume I would need to use a printer driver debug framework to find the issue but I don't know where to start but also have no time to debug this. Thank you anyway.Is there some Windows expert or someone you can tell me if I do things wrong? [...]https://docs.microsoft.com/en-us/windows/win32/cimwin32prov/win32-printerconfiguration
Oct 12 2021