Exemple #1
0
        private int ConfigureSmart51(int nres)
        {
            SmartComm2.SMART51_DEVMODE smdm;
            IntPtr smdm_ptr;
            Int32  dmlen     = Marshal.SizeOf(typeof(SmartComm2.SMART51_DEVMODE));
            IntPtr dmlen_ptr = Marshal.AllocHGlobal(dmlen);

            // allocate printer
            smdm_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SmartComm2.SMART51_DEVMODE)));
            Marshal.WriteInt32(dmlen_ptr, dmlen);

            // get current printer settings...
            if (nres == SmartComm2.SM_SUCCESS)
            {
                nres = SmartComm2.SmartComm_GetPrinterSettings2((long)hsmartprinterid, (int)smdm_ptr, (int)dmlen_ptr);
            }
            // set to both printing...
            smdm = (SmartComm2.SMART51_DEVMODE)Marshal.PtrToStructure(smdm_ptr, typeof(SmartComm2.SMART51_DEVMODE));
            smdm.devmode.dmOrientation = DMORIENT_LANDSCAPE;       // set landscape printing...
            smdm.oemdev.dwPrtSide      = SmartComm2.SMART_PRINTSIDE_BOTH;
            Marshal.StructureToPtr(smdm, smdm_ptr, true);
            // change printer settings...
            if (nres == SmartComm2.SM_SUCCESS)
            {
                nres = SmartComm2.SmartComm_SetPrinterSettings2((long)hsmartprinterid, (int)smdm_ptr, dmlen);
            }

            // free
            Marshal.FreeHGlobal(smdm_ptr);
            Marshal.FreeHGlobal(dmlen_ptr);
            return(nres);
        }