- Timestamp:
- Apr 8, 2003, 2:43:29 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/comdlg32/initcomdlg32.cpp
r9376 r9990 1 /* $Id: initcomdlg32.cpp,v 1. 4 2002-10-29 15:37:07sandervl Exp $ */1 /* $Id: initcomdlg32.cpp,v 1.5 2003-04-08 12:43:29 sandervl Exp $ */ 2 2 /* 3 3 * DLL entry point … … 54 54 switch (fdwReason) 55 55 { 56 case DLL_PROCESS_ATTACH: 57 { 58 //Write default printer name to win.ini 59 char achDefPrnName[256]; 60 if(PrfQueryProfileString(HINI_PROFILE, "PM_SPOOLER", "PRINTER", "", achDefPrnName, 61 sizeof(achDefPrnName)) > 1) 62 { 63 int len = strlen(achDefPrnName); 64 if(achDefPrnName[len-1] == ';') { 65 achDefPrnName[len-1] = 0; 56 case DLL_PROCESS_ATTACH: 57 { 58 /* 59 * Find default printer and write name to win.ini 60 * Format: queuename,driver,portname 61 */ 62 char szWinDefPrn[256]; 63 szWinDefPrn[0] = '\0'; 64 65 /* 66 * OS/2 stores the default printer as a combination of printerdevice and queue. 67 * 68 * Printer Device is related to one port. It may have multiple printer 69 * drivers because the port may serve multiple queues with different drivers. 70 * The Ports are related to multiple queues. 71 * 72 * So we take the default default printer+queue combination and finds the 73 */ 74 char szDefPrnDev[20]; 75 char szDefPrnQue[20]; 76 if (PrfQueryProfileString(HINI_PROFILE, "PM_SPOOLER", "PRINTER", "", 77 szDefPrnDev, sizeof(szDefPrnDev)) > 1 78 && PrfQueryProfileString(HINI_PROFILE, "PM_SPOOLER", "QUEUE", "", 79 szDefPrnQue, sizeof(szDefPrnQue)) > 1 80 && szDefPrnDev[0] 81 && szDefPrnQue[0] 82 ) 83 { 84 char *psz; 85 /* remove everything beyond the first ';' */ 86 if ((psz = strchr(szDefPrnDev, ';')) != NULL) 87 *psz = '\0'; 88 if ((psz = strchr(szDefPrnQue, ';')) != NULL) 89 *psz = '\0'; 90 91 /* 92 * Now we must lookup the port name from the device settings. 93 * This is a string of this form: 94 * <port>;<driver1>[,<driver2>;<queue1>[,<queue2>];?;?; 95 */ 96 ULONG cb = 0; 97 if (PrfQueryProfileSize(HINI_SYSTEMPROFILE, "PM_SPOOLER_PRINTER", szDefPrnDev, &cb) 98 && cb > 0) 99 { 100 char *pszBufD = (char*)malloc(cb + 1); 101 if (pszBufD 102 && PrfQueryProfileString(HINI_SYSTEMPROFILE, "PM_SPOOLER_PRINTER", szDefPrnDev, 103 NULL, pszBufD, cb + 1) 104 > 1 105 ) 106 { 107 /* 108 * Now get the Default printer driver for the queue. 109 * This is stored as a ';' separated list of drivers, the first one is the default. 110 */ 111 if (PrfQueryProfileSize(HINI_SYSTEMPROFILE, "PM_SPOOLER_QUEUE_DD", szDefPrnQue, &cb) 112 && cb > 0) 113 { 114 char *pszBufQ = (char*)malloc(cb + 1); 115 if (pszBufQ 116 && PrfQueryProfileString(HINI_SYSTEMPROFILE, "PM_SPOOLER_QUEUE_DD", szDefPrnQue, 117 NULL, pszBufQ, cb + 1) 118 > 1 119 ) 120 { 121 /* 122 * We got everything now. just find the parts we need. 123 * First printer driver from QUEUE_DD 124 * Port name of the device. 125 */ 126 if ((psz = strchr(pszBufQ, ';')) != NULL) 127 *psz = '\0'; 128 if ((psz = strchr(pszBufQ, ',')) != NULL) //paranoia! in case comman separated list of some kind. 129 *psz = '\0'; 130 if ((psz = strchr(pszBufD, ';')) != NULL) 131 *psz = '\0'; 132 if ((psz = strchr(pszBufD, ',')) != NULL) //paranoia in case comman separated list of some kind. 133 *psz = '\0'; 134 135 /* 136 * Now make default printer string for the win.ini. 137 */ 138 strcpy(szWinDefPrn, szDefPrnQue); 139 strcat(strcat(szWinDefPrn, ","), pszBufQ); 140 strcat(strcat(szWinDefPrn, ","), pszBufD); 141 dprintf(("LibMainComdlg32: Successfully found default printer.'%s'", szWinDefPrn)); 142 free(pszBufQ); 143 } 144 } 145 else 146 { 147 /* OS/2 the device may exist though the default queue is destroyed. 148 * it may still exist even if there are no queues on the system at all! 149 */ 150 dprintf(("LibMainComdlg32: no queue driver entry for '%s'.", szDefPrnQue)); 151 } 152 153 free(pszBufD); 154 } 66 155 } 67 strcat(achDefPrnName, ","); 68 WriteProfileStringA("windows", "device", achDefPrnName); 69 } 70 return COMDLG32_DllEntryPoint(hinstDLL, fdwReason, fImpLoad); 71 } 156 else 157 { 158 /* OS/2 doesn't remove the default settings if the default queue/printer is deleted. */ 159 dprintf(("LibMainComdlg32: can't find device settings for '%s'.", szDefPrnDev)); 160 } 161 } 162 else 163 { 164 dprintf(("LibMainComdlg32: no default printer? szDefPrnDev='%s' szDefPrnQue='%s'.", szDefPrnDev, szDefPrnQue)); 165 } 166 167 //Now get real printer name the one that will be used in DC calls 168 WriteProfileStringA("windows", "device", szWinDefPrn); 169 170 return COMDLG32_DllEntryPoint(hinstDLL, fdwReason, fImpLoad); 171 } 72 172 73 173 case DLL_THREAD_ATTACH: … … 105 205 if(dllHandle == 0) 106 206 return 0UL; 107 207 108 208 break; 109 209 case 1 :
Note:
See TracChangeset
for help on using the changeset viewer.