|
|
1.1 ! root 1: /************************************************************************* ! 2: ** ! 3: ** OLE 2 Standard Utilities ! 4: ** ! 5: ** olestd.c ! 6: ** ! 7: ** This file contains utilities that are useful for dealing with ! 8: ** target devices. ! 9: ** ! 10: ** (c) Copyright Microsoft Corp. 1992 All Rights Reserved ! 11: ** ! 12: *************************************************************************/ ! 13: ! 14: #define STRICT 1 ! 15: #include "ole2ui.h" ! 16: #ifndef WIN32 ! 17: #include <print.h> ! 18: #endif ! 19: ! 20: /* ! 21: * OleStdCreateDC() ! 22: * ! 23: * Purpose: ! 24: * ! 25: * Parameters: ! 26: * ! 27: * Return Value: ! 28: * SCODE - S_OK if successful ! 29: */ ! 30: STDAPI_(HDC) OleStdCreateDC(DVTARGETDEVICE FAR* ptd) ! 31: { ! 32: HDC hdc=NULL; ! 33: LPDEVNAMES lpDevNames; ! 34: LPDEVMODE lpDevMode; ! 35: LPSTR lpszDriverName; ! 36: LPSTR lpszDeviceName; ! 37: LPSTR lpszPortName; ! 38: ! 39: if (ptd == NULL) { ! 40: hdc = CreateDC("DISPLAY", NULL, NULL, NULL); ! 41: goto errReturn; ! 42: } ! 43: ! 44: lpDevNames = (LPDEVNAMES) ptd; // offset for size field ! 45: ! 46: if (ptd->tdExtDevmodeOffset == 0) { ! 47: lpDevMode = NULL; ! 48: }else{ ! 49: lpDevMode = (LPDEVMODE) ((LPSTR)ptd + ptd->tdExtDevmodeOffset); ! 50: } ! 51: ! 52: lpszDriverName = (LPSTR) lpDevNames + ptd->tdDriverNameOffset; ! 53: lpszDeviceName = (LPSTR) lpDevNames + ptd->tdDeviceNameOffset; ! 54: lpszPortName = (LPSTR) lpDevNames + ptd->tdPortNameOffset; ! 55: ! 56: hdc = CreateDC(lpszDriverName, lpszDeviceName, lpszPortName, lpDevMode); ! 57: ! 58: errReturn: ! 59: return hdc; ! 60: } ! 61: ! 62: ! 63: /* ! 64: * OleStdCreateIC() ! 65: * ! 66: * Purpose: Same as OleStdCreateDC, except that information context is ! 67: * created, rather than a whole device context. (CreateIC is ! 68: * used rather than CreateDC). ! 69: * OleStdDeleteDC is still used to delete the information context. ! 70: * ! 71: * Parameters: ! 72: * ! 73: * Return Value: ! 74: * SCODE - S_OK if successful ! 75: */ ! 76: STDAPI_(HDC) OleStdCreateIC(DVTARGETDEVICE FAR* ptd) ! 77: { ! 78: HDC hdcIC=NULL; ! 79: LPDEVNAMES lpDevNames; ! 80: LPDEVMODE lpDevMode; ! 81: LPSTR lpszDriverName; ! 82: LPSTR lpszDeviceName; ! 83: LPSTR lpszPortName; ! 84: ! 85: if (ptd == NULL) { ! 86: hdcIC = CreateIC("DISPLAY", NULL, NULL, NULL); ! 87: goto errReturn; ! 88: } ! 89: ! 90: lpDevNames = (LPDEVNAMES) ptd; // offset for size field ! 91: ! 92: lpDevMode = (LPDEVMODE) ((LPSTR)ptd + ptd->tdExtDevmodeOffset); ! 93: ! 94: lpszDriverName = (LPSTR) lpDevNames + ptd->tdDriverNameOffset; ! 95: lpszDeviceName = (LPSTR) lpDevNames + ptd->tdDeviceNameOffset; ! 96: lpszPortName = (LPSTR) lpDevNames + ptd->tdPortNameOffset; ! 97: ! 98: hdcIC = CreateIC(lpszDriverName, lpszDeviceName, lpszPortName, lpDevMode); ! 99: ! 100: errReturn: ! 101: return hdcIC; ! 102: } ! 103: ! 104: ! 105: /* ! 106: * OleStdCreateTargetDevice() ! 107: * ! 108: * Purpose: ! 109: * ! 110: * Parameters: ! 111: * ! 112: * Return Value: ! 113: * SCODE - S_OK if successful ! 114: */ ! 115: STDAPI_(DVTARGETDEVICE FAR*) OleStdCreateTargetDevice(LPPRINTDLG lpPrintDlg) ! 116: { ! 117: DVTARGETDEVICE FAR* ptd=NULL; ! 118: LPDEVNAMES lpDevNames, pDN; ! 119: LPDEVMODE lpDevMode, pDM; ! 120: UINT nMaxOffset; ! 121: LPSTR pszName; ! 122: DWORD dwDevNamesSize, dwDevModeSize, dwPtdSize; ! 123: ! 124: if ((pDN = (LPDEVNAMES)GlobalLock(lpPrintDlg->hDevNames)) == NULL) { ! 125: goto errReturn; ! 126: } ! 127: ! 128: if ((pDM = (LPDEVMODE)GlobalLock(lpPrintDlg->hDevMode)) == NULL) { ! 129: goto errReturn; ! 130: } ! 131: ! 132: nMaxOffset = (pDN->wDriverOffset > pDN->wDeviceOffset) ? ! 133: pDN->wDriverOffset : pDN->wDeviceOffset ; ! 134: ! 135: nMaxOffset = (pDN->wOutputOffset > nMaxOffset) ? ! 136: pDN->wOutputOffset : nMaxOffset ; ! 137: ! 138: pszName = (LPSTR)pDN + nMaxOffset; ! 139: ! 140: dwDevNamesSize = (DWORD)(nMaxOffset+lstrlen(pszName) + 1/* NULL term */); ! 141: dwDevModeSize = (DWORD) (pDM->dmSize + pDM->dmDriverExtra); ! 142: ! 143: dwPtdSize = sizeof(DWORD) + dwDevNamesSize + dwDevModeSize; ! 144: ! 145: if ((ptd = (DVTARGETDEVICE FAR*)OleStdMalloc(dwPtdSize)) != NULL) { ! 146: ! 147: // copy in the info ! 148: ptd->tdSize = (UINT)dwPtdSize; ! 149: ! 150: lpDevNames = (LPDEVNAMES) &ptd->tdDriverNameOffset; ! 151: _fmemcpy(lpDevNames, pDN, (size_t)dwDevNamesSize); ! 152: ! 153: lpDevMode=(LPDEVMODE)((LPSTR)&ptd->tdDriverNameOffset+dwDevNamesSize); ! 154: _fmemcpy(lpDevMode, pDM, (size_t)dwDevModeSize); ! 155: ! 156: ptd->tdDriverNameOffset += 4 ; ! 157: ptd->tdDeviceNameOffset += 4 ; ! 158: ptd->tdPortNameOffset += 4 ; ! 159: ptd->tdExtDevmodeOffset = (UINT)dwDevNamesSize + 4 ; ! 160: } ! 161: ! 162: errReturn: ! 163: GlobalUnlock(lpPrintDlg->hDevNames); ! 164: GlobalUnlock(lpPrintDlg->hDevMode); ! 165: ! 166: return ptd; ! 167: } ! 168: ! 169: ! 170: ! 171: /* ! 172: * OleStdDeleteTargetDevice() ! 173: * ! 174: * Purpose: ! 175: * ! 176: * Parameters: ! 177: * ! 178: * Return Value: ! 179: * SCODE - S_OK if successful ! 180: */ ! 181: STDAPI_(BOOL) OleStdDeleteTargetDevice(DVTARGETDEVICE FAR* ptd) ! 182: { ! 183: BOOL res=TRUE; ! 184: ! 185: if (ptd != NULL) { ! 186: OleStdFree(ptd); ! 187: } ! 188: ! 189: return res; ! 190: } ! 191: ! 192: ! 193: ! 194: /* ! 195: * OleStdCopyTargetDevice() ! 196: * ! 197: * Purpose: ! 198: * duplicate a TARGETDEVICE struct. this function allocates memory for ! 199: * the copy. the caller MUST free the allocated copy when done with it ! 200: * using the standard allocator returned from CoGetMalloc. ! 201: * (OleStdFree can be used to free the copy). ! 202: * ! 203: * Parameters: ! 204: * ptdSrc pointer to source TARGETDEVICE ! 205: * ! 206: * Return Value: ! 207: * pointer to allocated copy of ptdSrc ! 208: * if ptdSrc==NULL then retuns NULL is returned. ! 209: * if ptdSrc!=NULL and memory allocation fails, then NULL is returned ! 210: */ ! 211: STDAPI_(DVTARGETDEVICE FAR*) OleStdCopyTargetDevice(DVTARGETDEVICE FAR* ptdSrc) ! 212: { ! 213: DVTARGETDEVICE FAR* ptdDest = NULL; ! 214: ! 215: if (ptdSrc == NULL) { ! 216: return NULL; ! 217: } ! 218: ! 219: if ((ptdDest = (DVTARGETDEVICE FAR*)OleStdMalloc(ptdSrc->tdSize)) != NULL) { ! 220: _fmemcpy(ptdDest, ptdSrc, (size_t)ptdSrc->tdSize); ! 221: } ! 222: ! 223: return ptdDest; ! 224: } ! 225: ! 226: ! 227: /* ! 228: * OleStdCopyFormatEtc() ! 229: * ! 230: * Purpose: ! 231: * Copies the contents of a FORMATETC structure. this function takes ! 232: * special care to copy correctly copying the pointer to the TARGETDEVICE ! 233: * contained within the source FORMATETC structure. ! 234: * if the source FORMATETC has a non-NULL TARGETDEVICE, then a copy ! 235: * of the TARGETDEVICE will be allocated for the destination of the ! 236: * FORMATETC (petcDest). ! 237: * ! 238: * OLE2NOTE: the caller MUST free the allocated copy of the TARGETDEVICE ! 239: * within the destination FORMATETC when done with it ! 240: * using the standard allocator returned from CoGetMalloc. ! 241: * (OleStdFree can be used to free the copy). ! 242: * ! 243: * Parameters: ! 244: * petcDest pointer to destination FORMATETC ! 245: * petcSrc pointer to source FORMATETC ! 246: * ! 247: * Return Value: ! 248: * pointer to allocated copy of ptdSrc; retuns NULL if not successful ! 249: */ ! 250: STDAPI_(BOOL) OleStdCopyFormatEtc(LPFORMATETC petcDest, LPFORMATETC petcSrc) ! 251: { ! 252: if ((petcDest == NULL) || (petcSrc == NULL)) { ! 253: return FALSE; ! 254: } ! 255: ! 256: petcDest->cfFormat = petcSrc->cfFormat; ! 257: petcDest->ptd = OleStdCopyTargetDevice(petcSrc->ptd); ! 258: petcDest->dwAspect = petcSrc->dwAspect; ! 259: petcDest->lindex = petcSrc->lindex; ! 260: petcDest->tymed = petcSrc->tymed; ! 261: ! 262: return TRUE; ! 263: ! 264: } ! 265:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.