I am trying to make a AddForm function using C++ Windows.h's Print Spooler API. I haven't find any C++ examples or couldn't figure out solution, so I wanted ask your help.
My code should done same as in this picture:
Source Material
- https://learn.microsoft.com/en-us/windows/win32/printdocs/addform
- https://learn.microsoft.com/en-us/windows/win32/api/windef/ns-windef-size
- https://www.codeproject.com/Articles/12229/Adding-Custom-Paper-Sizes-to-Named-Printers-2
- Use PrintSpoolerAPI function SetForm() in C#
Code input:
#include <iostream>
#include "Windows.h"
#include "Winspool.h"
using namespace std;
int main() {
LPHANDLE hPrinter = NULL;
OpenPrinter(
NULL,
hPrinter,
NULL
); // No critical error here: "hPrinter could be "0"
FORM_INFO_1 exampleform;
exampleform.Flags = 0;
exampleform.pName = (LPWSTR)"0A"; // No critical error here: "Cast between semantically different string types. Use of invalid string can lead to undefined behaviour."
exampleform.Size.cx = 1260 * 1000;
exampleform.Size.cy = 891 * 1000;
exampleform.ImageableArea.left = 0;
exampleform.ImageableArea.top = 0;
exampleform.ImageableArea.right = exampleform.Size.cx;
exampleform.ImageableArea.bottom = exampleform.Size.cy;
cout << exampleform.pName; //output as: "00007FF68EFA9C24"
AddForm(hPrinter, 1, reinterpret_cast<LPBYTE>(&exampleform)); // No critical error here : "hPrinter could be "0"
//C:\Users\XXX\source\repos\paperApp\x64\Debug\paperApp.exe (process 16792) exited with code 0.
}
Problem: The code looks good, but nothing really happens.
Thank you all for your responses!