registry.cpp
来自「HP喷墨打印机驱动代码 HP内部资料! 珍贵 珍贵 珍贵」· C++ 代码 · 共 629 行 · 第 1/2 页
CPP
629 行
j++; pen2 = pens[j]; } if(pen1 == 'A' || pen2 == 'A') { if(pen1 == 'A') { // 2-pen printer with both pens missing if(pen2 == 'A') pSS->DisplayPrinterStatus(DISPLAY_NO_PENS); // 1-pen printer with missing pen else if(pen2 == '\0') pSS->DisplayPrinterStatus(DISPLAY_NO_PEN_DJ600); // may be one-pen venice derivative else if (pen2 == 'F') { device = eDJ8x5; return NO_ERROR; } // 2-pen printer with BLACK missing else pSS->DisplayPrinterStatus(DISPLAY_NO_BLACK_PEN); } // 2-pen printer with COLOR missing else if(pen2 == 'A') {// Hoobes, Zorro or Linus, possibly Phobos derivative if (pen1 == 'H' || pen1 == 'Z' || pen1 == 'L') { device = eDJ8x5; return NO_ERROR; } pSS->DisplayPrinterStatus(DISPLAY_NO_COLOR_PEN); } if (pSS->BusyWait(500) == JOB_CANCELED) return JOB_CANCELED; // we must re-query the devID err=GetPrinterModel(model,pVIPVersion,pens,pSS); ERRCHECK; } } while(pen1 == 'A' || pen2 == 'A'); // now that we have pens to look at, let's do the logic // to instantiate the 'best-fit' driver if (pen1 == 'H' || pen1 == 'Z' || pen1 == 'L') // Hobbes, Zorro, Linus (BLACK) { // check for a 850/855/870 if (pen2 == 'M') // Monet (COLOR) device = eDJ850; else if (strncmp (model,"DESKJET 890",11) == 0) device=eDJ890; // 890 has same pens as Venice! else if (pen2 == 'N') // Chinook (COLOR) device = eDJ9xx; // It must be a Venice derivative or will hopefully at // least recognize a Venice print mode else device = eDJ8xx; } else if(pen1 == 'C') // Candide (BLACK) { // check for 1-pen printer if (pen2 == '\0') device = eDJ600; // must be a 2-pen 6xx-derivative else device = eDJ6xx; } else if(pen1 == 'M') // Multi-dye load { // must be a 690-derivative device = eDJ6xxPhoto; } // check for 540-style pens? // D = Kukla color, E = Triad black// else device=UNSUPPORTED; } } // Early Venice printer do not yet have full bi-di so check // the model to avoid a communication problem. if ( ( (strncmp(model,"DESKJET 81",10) == 0) || (strncmp(model,"DESKJET 83",10) == 0) || (strncmp(model,"DESKJET 88",10) == 0) || (strncmp(model,"DESKJET 895",11) == 0) ) && (pSS->IOMode.bUSB) ) { DBG1("This printer has limited USB status\n"); pSS->IOMode.bStatus = FALSE; pSS->IOMode.bDevID = FALSE; } if ( ( (strncmp(model,"DESKJET 63",10) == 0) || (strncmp(model,"DESKJET 64",10) == 0) ) && (pSS->IOMode.bUSB) ) { DBG1("This printer has limited USB status, but we did get DeviceIDString\n"); pSS->IOMode.bStatus = FALSE; } if (device == UNSUPPORTED) return UNSUPPORTED_PRINTER; else return NO_ERROR;} //SelectDeviceDRIVER_ERROR DeviceRegistry::SelectDevice(const char* sDevID, SystemServices* pSS){ char strModel[DevIDBuffSize]; // to contain the MODEL (MDL) from the DevID char strPens[64]; // to contain the VSTATUS penID from the DevID int VIPVersion; // VIP version from the DevID DRIVER_ERROR err = ParseDevIDString(sDevID, strModel, &VIPVersion, strPens); if (err != NO_ERROR) { return UNSUPPORTED_PRINTER; } return SelectDevice(strModel, &VIPVersion, strPens, pSS);}DRIVER_ERROR DeviceRegistry::InstantiatePrinter(Printer*& p, SystemServices* pSS)// Instantiate a printer object and return a pointer p based on the previously// set 'device' variable{ //ASSERT(p == NULL); // if it's not then we're going to loose memory FAMILY_HANDLE familyHandle = pPFI->FindDevIdMatch(ModelName[device]); if (familyHandle == NULL) { ASSERT(familyHandle); DBG1("DR::InstantiatePrinter - no family match\n"); return UNSUPPORTED_PRINTER; } p = pPFI->CreatePrinter(pSS, familyHandle); NEWCHECK(p); return p->constructor_error;} //InstantiatePrinterDRIVER_ERROR DeviceRegistry::GetPrinterModel(char* strModel, int *pVIPVersion, char* strPens, SystemServices* pSS){ DRIVER_ERROR err; BYTE DevIDBuffer[DevIDBuffSize]; err = pSS->GetDeviceID(DevIDBuffer, DevIDBuffSize, TRUE); ERRCHECK; // should be either NO_ERROR or BAD_DEVICE_ID return ParseDevIDString((const char*)DevIDBuffer, strModel, pVIPVersion, strPens);} //GetPrinterModel#define HEXTOINT(x, p) if (x >= '0' && x <= '9') *p |= x - '0'; \ else if (x >= 'A' && x <= 'F') *p |= 0xA + x - 'A'; \ else if (x >= 'a' && x <= 'f') *p |= 0xA + x - 'a'//ParseDevIDString//! Parse a device id string/*!Enter a full description of the method here. This will be the API doc.******************************************************************************/DRIVER_ERROR DeviceRegistry::ParseDevIDString(const char* sDevID, char* strModel, int *pVIPVersion, char* strPens){ int i; // simple counter char* pStr = NULL; // string pointer used in parsing DevID // get the model name // - note: I'm setting pStr to the return of strstr // so I need to increment past my search string if ( (pStr = (char *)strstr(sDevID+2,"MODEL:")) ) pStr+=6; else if ( (pStr=(char *)strstr(sDevID+2,"MDL:")) ) pStr+=4; else return BAD_DEVICE_ID; // my own version of strtok to pull out the model string here i = 0; while ( (pStr[i] != ';') && (pStr[i] != '\0') && (i < DevIDBuffSize)) { strModel[i] = pStr[i]; i++; } strModel[i] = '\0'; // see if this printer support VIP or not if ( (pStr=(char *)strstr(sDevID+2,";S:00")) ) // binary encoded device ID status (version 0) { pStr += 15; // get to the VIP support field (version of 0 == doesn't support VIP) if ((*pStr >= '0') && (*pStr <= '9')) { *pVIPVersion = *pStr - '0'; } else if ((*pStr >= 'A') && (*pStr <= 'F')) { *pVIPVersion = 10 + (*pStr - 'A'); } else { *pVIPVersion = 0; } }/* * DevID string has changed starting with Jupiter. * Following ";S:", two nibbles for Version Number * 12 nibbles for Status Information, the last nibble * is reserved for future use, the second from last * indicates whether the printer has VIP support. * * Actually, four nibbles were added. * The first fourteen nibbles contain feature state info. * So, starting with version 02 of device id, following ":S:" there are * 2 nibbles for version number * 14 nibbles for feature state (the 15th nibble from ';' is the vip flag * 2 nibbles for printer status * * Crystal added 4 more nibbles to the option field. */ else if ((pStr = (char *)strstr (sDevID+2, ";S:"))) { *pVIPVersion = 0; HEXTOINT (*(pStr+3), pVIPVersion); *pVIPVersion = *pVIPVersion << 4; HEXTOINT (*(pStr+4), pVIPVersion); if (*(pStr + 15) == '1') { (*pVIPVersion)++; } else { *pVIPVersion = 0; } } else { *pVIPVersion = 0; } // now get the pen info if( (pStr=(char *)strstr(sDevID+2,"VSTATUS:")) ) { pStr+=8; i=0; while ( (pStr[i] != ',') && (pStr[i] != ';') && (pStr[i] != '\0') ) { strPens[i] = pStr[i]; i++; } strPens[i] = '\0'; } else if ( (pStr = (char *)strstr(sDevID + 2, ";S:00")) || // binary encoded device ID status (version 0) (pStr = (char *)strstr (sDevID + 2, ";S:"))) // Jupiter and later style { int iVersion = 0; HEXTOINT (*(pStr+3), &iVersion); iVersion = iVersion << 4; HEXTOINT (*(pStr+4), &iVersion); if (iVersion <= 2) { pStr += 19; // get to the number of pens field } else if (iVersion < 4) { pStr += 21; } else { pStr += 25; } // each supported pen has a block of 8 bytes of info so copy the number of pens byte // plus 8 bytes for each supported ped if ((*pStr >= '0') && (*pStr <= '9')) { i = 1 + ((*pStr-'0')*8); } else if ((*pStr >= 'A') && (*pStr <= 'F')) { i = 1 + ((10 + (*pStr-'A')) * 8); } else { // bogus number of pens field i = 1; } memcpy(strPens, pStr, i); strPens[i] = '\0'; } else // no VSTATUS for 400 and sleek printers strPens[0] = '\0'; return NO_ERROR;} //ParseDevIDStringAPDK_END_NAMESPACE
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?