hello monks
There is the GetPrinter Win32 api function (which retrieves information on a printer)
that requires a pointer to a PRINTER_INFO_2 structure.
The structure is defined as :
typedef struct _PRINTER_INFO_2 {
LPTSTR pServerName;
LPTSTR pPrinterName;
LPTSTR pShareName;
LPTSTR pPortName;
LPTSTR pDriverName;
LPTSTR pComment;
LPTSTR pLocation;
LPDEVMODE pDevMode;
LPTSTR pSepFile;
LPTSTR pPrintProcessor;
LPTSTR pDatatype;
LPTSTR pParameters;
PSECURITY_DESCRIPTOR pSecurityDescriptor;
DWORD Attributes;
DWORD Priority;
DWORD DefaultPriority;
DWORD StartTime;
DWORD UntilTime;
DWORD Status;
DWORD cJobs;
DWORD AveragePPM;
} PRINTER_INFO_2, *PPRINTER_INFO_2;
which I packed it into $printer_info_2 variable as :
$a="\0";
$printer_info_2=pack('PPPPPPPPPPPPPLLLLLLLL',$a,$a,$a,$a,$a,$a,$a,$a,$
+a,$a,$a,$a,$a,0,0,0,0,0,0,0,0);
then I load and call the function :
$GetPrinter=new Win32::API('winspool.drv','GetPrinterA','NNPNP','N');
$GetPrinter->Call($handle,2,$printer_info_2,10000,$bytesgot);
and then unpack as :
@a=unpack('P32P32P32P32P32P32P32P32P32P32P32P32P32LLLLLLLL',$printer_i
+nfo_2);
I do get data,but they are mixed or overlap hence they cannot lead to a solid view of the printer's details
data output :
\\http://192.168.4.98\Lexmark T4
\\http://192.168.4.98\Lexmark
http://192.168.4.98 . 1 6 8 . 4
Lexmark T430 T 4 3 0 http:/
comments go here g o h e r e
comments go here g o h e r
\\http://192.168.4.98\Lexmark
comments go here g o h e
WinPrint i n t comments g
RAW W WinPrint i n t co
RAW W WinPrint i n t
€ \ \ h t t p
2128
1
0
1380
1380
0
0
0
So this raises the question:
Is that the correct way to define and unpack pointers to strings? I don't know the length of the string that is why I use a number like 32.
I tried to pack and unpack using 'p' instead of 'P' but it makes the application crash!
Plus,how do I implement a pointer to a structure,where the pointer itself is part of another structure? (such as LPDEVMODE)
During my research I've seen pointers to strings being packed as 'L' and unpacked as 'p'.But it is all so confusing!
Any answers or any hints to get me started are gladly appreciated!Thanks!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.