Click here to Skip to main content
15,898,035 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Will you someone recommend books on C and C++? Pin
Sarath C12-Jan-09 16:27
Sarath C12-Jan-09 16:27 
GeneralRe: Will you someone recommend books on C and C++? Pin
Luc Pattyn12-Jan-09 8:12
sitebuilderLuc Pattyn12-Jan-09 8:12 
AnswerRe: Will you someone recommend books on C and C++? Pin
Jijo.Raj12-Jan-09 10:49
Jijo.Raj12-Jan-09 10:49 
AnswerRe: Will you someone recommend books on C and C++? Pin
Loreia13-Jan-09 8:19
Loreia13-Jan-09 8:19 
QuestionRegistryKeys in MFC Pin
Software200712-Jan-09 7:40
Software200712-Jan-09 7:40 
AnswerRe: RegistryKeys in MFC Pin
Mark Salsbery12-Jan-09 8:13
Mark Salsbery12-Jan-09 8:13 
AnswerRe: RegistryKeys in MFC Pin
Iain Clarke, Warrior Programmer12-Jan-09 8:15
Iain Clarke, Warrior Programmer12-Jan-09 8:15 
QuestionAddPrinter Windows API call help Pin
TaffyApple12-Jan-09 7:28
TaffyApple12-Jan-09 7:28 
Hi guys,

I'm attempting to add network printers to a local machine, only I've run into some trouble with the AddPrinter call. Essentially it returns 0 for the handle and doesn't tell me anything with GetLastError - I read somewhere this is a bug in the API, but don't know if its still there ( although, it appears so !)

Code goes like so:

PRINTER_INFO_2 *pi1=NULL;
DWORD size(0), numOfPrinters(0);

EnumPrinters(PRINTER_ENUM_NAME, (LPSTR)strPrintServerName.c_str(), 2, NULL, 0, (LPDWORD)&size, (LPDWORD)&numOfPrinters);

pi1 = new PRINTER_INFO_2[numOfPrinters+1];

if (EnumPrinters(PRINTER_ENUM_NAME, (LPSTR)strPrintServerName.c_str(), 2, (LPBYTE)pi1, size, (LPDWORD)&size, (LPDWORD)&numOfPrinters))
{

  for(unsigned int i=0; i<numOfPrinters; i++)
  {
    PRINTER_INFO_2 *pi2 = &pi1[i];
    std::cout << pi2->pPrinterName << std::endl;

    HANDLE hPrinter(0);

    hPrinter = AddPrinter(pi2->pPrinterName, 2, (LPBYTE)pi2);
    if (hPrinter != 0)
    {
      std::cout << "Printer handle " << hPrinter << std::endl;
    }
    else
    {
      std::cout << "Failed to add printer " << pi2->pPrinterName << std::endl;
    }
  }
}
else
{
  std::cout << "Enum Call failed - " << GetLastError() << std::endl;
}

delete [] pi1;



Any help you can offer would be much appreciated!

Andrew
AnswerRe: AddPrinter Windows API call help Pin
Graham Bradshaw12-Jan-09 12:25
Graham Bradshaw12-Jan-09 12:25 
GeneralRe: AddPrinter Windows API call help Pin
TaffyApple12-Jan-09 21:47
TaffyApple12-Jan-09 21:47 
GeneralRe: AddPrinter Windows API call help Pin
Graham Bradshaw12-Jan-09 22:16
Graham Bradshaw12-Jan-09 22:16 
GeneralRe: AddPrinter Windows API call help Pin
TaffyApple13-Jan-09 1:43
TaffyApple13-Jan-09 1:43 
GeneralRe: AddPrinter Windows API call help Pin
Graham Bradshaw13-Jan-09 2:21
Graham Bradshaw13-Jan-09 2:21 
GeneralRe: AddPrinter Windows API call help Pin
TaffyApple13-Jan-09 3:00
TaffyApple13-Jan-09 3:00 
QuestionRight to Left alignment of the DialogBox i Pin
Alex@9C12-Jan-09 6:58
Alex@9C12-Jan-09 6:58 
QuestionFlushing the content of an std::wstring to an UTF-8 encoded text file .. [SOLVED] Pin
Ahmed Charfeddine12-Jan-09 5:38
Ahmed Charfeddine12-Jan-09 5:38 
AnswerRe: Flushing the content of an std::wstring to an UTF-8 encoded text file .. Pin
Mark Salsbery12-Jan-09 7:01
Mark Salsbery12-Jan-09 7:01 
GeneralRe: Flushing the content of an std::wstring to an UTF-8 encoded text file .. Pin
Ahmed Charfeddine14-Jan-09 7:06
Ahmed Charfeddine14-Jan-09 7:06 
GeneralRe: Flushing the content of an std::wstring to an UTF-8 encoded text file .. Pin
Mark Salsbery14-Jan-09 7:24
Mark Salsbery14-Jan-09 7:24 
Questionatomic file write Pin
Dave_12-Jan-09 5:00
Dave_12-Jan-09 5:00 
AnswerRe: atomic file write Pin
Rajasekharan Vengalil12-Jan-09 5:21
Rajasekharan Vengalil12-Jan-09 5:21 
GeneralRe: atomic file write Pin
Dave_12-Jan-09 7:21
Dave_12-Jan-09 7:21 
GeneralRe: atomic file write Pin
Rajasekharan Vengalil12-Jan-09 7:29
Rajasekharan Vengalil12-Jan-09 7:29 
GeneralRe: atomic file write Pin
Dave_12-Jan-09 7:31
Dave_12-Jan-09 7:31 
GeneralRe: atomic file write Pin
Rajasekharan Vengalil12-Jan-09 9:11
Rajasekharan Vengalil12-Jan-09 9:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.