コード例 #1
0
        private PrinterNotifyInfoData GetInfoData(int index)
        {
            // Need to figure out where the location must be set in order to find PrinterNotifyInfoData objects.
            // This location can be subtly different based on what bitness the OS is running.
            // For this reason, the true "size" of object is the marshal size, plus however many bytes gets us
            // to the next memory boundary.  The size of IntPtr indicates what the memory boundary is for the given OS.
            int sizeOfInfo = Marshal.SizeOf <PrinterNotifyInfo>();

            sizeOfInfo += (sizeOfInfo % Marshal.SizeOf <IntPtr>());

            int sizeOfData = Marshal.SizeOf <PrinterNotifyInfoData>();

            sizeOfData += (sizeOfData % Marshal.SizeOf <IntPtr>());

            long location = _infoHandle.DangerousGetHandle().ToInt64() + sizeOfInfo + (sizeOfData * index);

            return(Marshal.PtrToStructure <PrinterNotifyInfoData>(new IntPtr(location)));
        }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PrinterNotifyInfoReader"/> class.
 /// </summary>
 /// <param name="infoHandle">The handle to a <see cref="PrinterNotifyInfo" />.</param>
 public PrinterNotifyInfoReader(SafePrinterNotifyInfoHandle infoHandle)
 {
     _infoHandle = infoHandle;
     Info        = Marshal.PtrToStructure <PrinterNotifyInfo>(infoHandle.DangerousGetHandle());
 }