1 Replies - 4030 Views - Last Post: 05 March 2014 - 04:56 PM Rate Topic: -----

#1 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 770
  • View blog
  • Posts: 2,249
  • Joined: 20-March 10

Getting Default Printer Name in Windows

Post icon  Posted 05 March 2014 - 09:59 AM

I have submitted this as though there is info on msdn it is not immediately obvious how to use the GetDefaultPrinter function under windows as you have to call the function twice. Once to get the buffer size and second time to retrieve the printer name and set the buffer size.

#include <Windows.h>
#include <stdio.h>
#pragma comment(lib,"Winspool.lib")

int main()
{
	
	char input;
	unsigned int i = 0;
	DWORD bufferSize=0;
	BOOL result = FALSE;
	result = GetDefaultPrinter(NULL,&bufferSize); // get size of buffer
	char* printerName = (char*)malloc(sizeof(char)*bufferSize);
	result = GetDefaultPrinter(printerName,&bufferSize); //set size of buffer and get Printer Name
	
	if(result!=0)
	printf("Default Printer is %s\n",printerName);
	else
	printf("Error: Default Printer not returned\n");

	scanf(&input);//used to hold window open replace as you see fit
	free(printerName);
	return 0;
}



Is This A Good Question/Topic? 2
  • +

Replies To: Getting Default Printer Name in Windows

#2 Michael26  Icon User is offline

  • DIC-head, major DIC-head
  • member icon

Reputation: 355
  • View blog
  • Posts: 1,521
  • Joined: 08-April 09

Re: Getting Default Printer Name in Windows

Posted 05 March 2014 - 04:56 PM

Useful info
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1