Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Glenn Duncan   on Oct 06 In MS Office Category.

  
Question Answered By: Leo Evans   on Oct 06

Well, the key here is the Win32 API EnumPrinters.

msdn.microsoft.com/.../prntspo
l_9fjn.asp

Lots of info  there.

The key is that EnumPrinters returns data  into a buffer of either type
PRINTER_INFO_1, PRINTER_INFO_2, PRINTER_INFO_4, or PRINTER_INFO_5. There are
links to these data structures in the above article.

The docs, which should be read  carefully if you’re going to try to use this,
indicate that you have your choice of which PRINTER_INFO data structure you
want to return. It recommends PRINTER_INFO_4 as the one to use because it’s
the quickest and most lightweight. Your code is using PRINTER_INFO_1, as
determined by the 3rd parameter in the EnumPrinters call. PRINTER_INFO_1 may
work fine too.



PRINTER_INFO_4 docs:

msdn.microsoft.com/.../prntspo
l_8vle.asp

PRINTER_INFO_4 just has the printer  name, the server name, and a
local/network attribute. MAYBE the server name is what you need. I don’t
know, haven’t tried it.

However, the docs also say that it just gets this info right out of the
registry, so if you find that easier, there you go.



In order to user  PRINTER_INFO_4 instead of PRINTER_INFO_1, you’ll need to
change iBufferSize to the correct number of bytes for the data structure (I
don’t know what that is), and you’ll also need to hack up the result using
code similar to what you currently have after the comment in your code that
says “get printer name”. I don’t know if that kind of byte-twiddle coding is
within your scope or not.



It may just be easier to pull the info from the Registry – I’m finding the
exact info you want at:

HKCU\Software\Microsoft\Windows NT\Current Version\Devices

It’s got the port  name and everything.

HKCU\Software\Microsoft\Windows NT\Current Version\PrinterPorts

has most of the same info, but with some extra timeout values, probably
unnecessary for your purposes.

I would go with the registry…

Share: 

 

This Question has 2 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Print Control From A Combo Box Value Or get search suggestion and latest updates.


Tagged: