IntPtr CreatePrinterDC(ref PAGESETUPDLGSTRUCT lppsd) { // Create managed structure for DEVNAMES DEVNAMES dn = new DEVNAMES(); Marshal.PtrToStructure(lppsd.hDevNames, dn); // Get base address of native structure int iBase = (int)lppsd.hDevNames; // Get pointer to driver name. IntPtr iptrDriver = (IntPtr)(iBase + dn.wDriverOffset); string strDriver = Marshal.PtrToStringUni(iptrDriver); // Get pointer to device name. IntPtr iptrDevice = (IntPtr)(iBase + dn.wDeviceOffset); string strDevice = Marshal.PtrToStringUni(iptrDevice); // Get pointer to output port. IntPtr iptrOutput = (IntPtr)(iBase + dn.wOutputOffset); string strOutput = Marshal.PtrToStringUni(iptrOutput); IntPtr hdc = CreateDC(iptrDriver, iptrDevice, iptrOutput, lppsd.hDevMode); return(hdc); }
string QueryOutputPort(ref PAGESETUPDLGSTRUCT lppsd) { // Create managed structure for DEVNAMES DEVNAMES dn = new DEVNAMES(); Marshal.PtrToStructure(lppsd.hDevNames, dn); // Get base address of native structure int iBase = (int)lppsd.hDevNames; // Get pointer to output port. IntPtr iptrOutput = new IntPtr(iBase + dn.wOutputOffset); string strOutput = Marshal.PtrToStringUni(iptrOutput); return(strOutput); }