Originally Posted by
algorism
You still haven't explained where le_printer comes from.
OK, this is lengthy.
Here's the func that opens the printer based on its name and returns the handle to php:
Code:
PHP_FUNCTION(printer_open)
{
zval *arg1;
printer *resource;
int argc = ZEND_NUM_ARGS();
resource = (printer *)emalloc(sizeof(printer));
resource->dmModifiedFields = 0;
if( argc == 1 && zend_get_parameters_ex(1, &arg1) != FAILURE ) {
convert_to_string_ex(arg1);
resource->name = Z_STRVAL_P(arg1);
}
else if( argc == 0 ) {
resource->name = PRINTER7_G(default_printer);
}
else {
WRONG_PARAM_COUNT;
}
if (OpenPrinter(resource->name, &resource->handle, NULL) != 0) {
resource->pi2 = (PRINTER_INFO_2 *)emalloc(sizeof(PRINTER_INFO_2));
resource->pi2->pDevMode = (DEVMODE *)emalloc(DocumentProperties(NULL, NULL, resource->name, NULL, NULL, 0));
if (DocumentProperties(NULL, resource->handle, resource->name, resource->pi2->pDevMode, NULL, DM_OUT_BUFFER) == IDOK) {
resource->info.lpszDocName = estrdup("PHP generated Document");
resource->info.lpszOutput = NULL;
resource->info.lpszDatatype = estrdup("TEXT");
resource->info.fwType = 0;
resource->info.cbSize = sizeof(resource->info);
resource->dc = CreateDC(NULL, resource->name, NULL, resource->pi2->pDevMode);
RETURN_RES(zend_register_resource(resource, le_printer));
}
}
else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "couldn't connect to the printer [%s]", resource->name);
RETURN_FALSE;
}
}
Here's the php that retrieves the handle from the above function and then uses the handle returned to call printer_get_papersources which is the function we've been working on:
Code:
$hndlPrinter = printer_open($PrinterName);
$sRtn = printer_get_papersources($hndlPrinter);
I use the printer_open with success to print basic text and (as you know) to list the printer's fonts.