Last night I wrote a little application that tries to get printer information using the EnumPrinters() API function. It also shows how to use an array when you have to deal with weird data structures like 'pointer to ANY' or multiple null-terminated strings (described below.) You can download the app (with source code) from ftp://ftp.gisnet.com/pub/PrinterEnum.zip.
It works, but there's more to do to make it squeaky clean. Although I was able to retrieve all the printer data and display it, I haven't yet been able to match up the PRINTER_INFO_1 pointers to the correct strings. The data are arranged in an odd way, and on Win NT/2000/XP systems there's some data packing issues and some of the text appears in Unicode format. If anyone can sort that part out and tell me how to handle it, I'd appreciate it. It was indeed an 'interesting little hack.' -- - Bill Thoen ------------------------------------------------------------ GISnet, 1401 Walnut St., Suite C, Boulder, CO 80302 tel: 303-786-9961, fax: 303-443-4856 http://www.gisnet.com/ ------------------------------------------------------------ Bill Thoen wrote: > > "Driver, Greg 9434" wrote: > > l_9fjn.asp . Using these examples (especially the first) I've been able to > > get it work in VB but not in MapBasic. In MapBasic I just get the first > > printer name returned in my string but not the other two that should appear! > > Aaargh! > > If you get desperate enough to need to read blocks of string data > separated by nulls (like these) from an API in MapBasic, you can > try passing an array of small integers to the function instead of > a string type. In MapBasic strings get terminated by a null, and > so you only see the first one, but with an array of small > integers these nulls are just zeroes and they don't cut the data > short like they do with strings. > > Change the API declaration to accept an array instead of a > string, make sure the array is dimensioned large enough, and call > the API function. On return, the values in the high and low bytes > of each array element are really the ANSI codes for the > characters in what would have been a string. So you just read > them out if the array (in low byte- high byte order) and convert > to characters with Chr$(), skipping over the zeroes and you'll > get your strings. > > Yes, it's more work but it's an interesting little hack. > > - Bill Thoen --------------------------------------------------------------------- List hosting provided by Directions Magazine | www.directionsmag.com | To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] Message number: 10378
