Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include "windows.h"
- #define PRINTER_NAME "Samsung CLX-216x Series"
- #define USB_PRINTER_ADDRESS "268435467"
- int main(int argc, char* argv[]) {
- HANDLE hPrinter = INVALID_HANDLE_VALUE;
- HANDLE hChangeNotificationObject = INVALID_HANDLE_VALUE;
- printf("INFO: Starting...\n");
- // initialize
- if (OpenPrinter(PRINTER_NAME, &hPrinter, NULL) == 0) {
- printf("ERR: Could not open printer\n");
- exit(1);
- } else {
- printf("INFO: Printer handle is 0x%08X\n", hPrinter);
- }
- hChangeNotificationObject = FindFirstPrinterChangeNotification(hPrinter, PRINTER_CHANGE_JOB, 0, NULL);
- if (hChangeNotificationObject == INVALID_HANDLE_VALUE) {
- printf("ERR: Could not get a notification object\n");
- } else {
- printf("INFO: notification object handle is 0x%08X\n", hChangeNotificationObject);
- }
- printf("Waiting for change notification... Try to print something like the test page...\n");
- WaitForSingleObject(hChangeNotificationObject, INFINITE);
- // we've got an event... connect the USB port via API
- system("vhui64.exe -t \"USE," USB_PRINTER_ADDRESS "\"");
- // cleanup
- if (hChangeNotificationObject != INVALID_HANDLE_VALUE) {
- if (FindClosePrinterChangeNotification(hChangeNotificationObject) == 0) {
- printf("ERR: Could not close notification object\n");
- } else {
- printf("INFO: Notification object closed\n");
- }
- }
- if (hPrinter != INVALID_HANDLE_VALUE) {
- if (ClosePrinter(hPrinter) == 0) {
- printf("ERR: Could not close printer\n");
- } else {
- printf("INFO: Printer handle closed\n");
- }
- }
- printf("INFO: done.\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement