'フォーム Imports System.Runtime.InteropServices Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim PD As New System.Drawing.Printing.PrintDocument Dim PrinterName As String Dim PrnD As PRINTER_DEFAULTS Dim PrinterHandle As Long Dim Result As Long Dim Needed As Integer Dim pPrinterInfo As IntPtr = IntPtr.Zero 'Dim pi2_buffer() As Long Dim PrinterInfo As PRINTER_INFO_2 Dim pFullDevMode As Long Dim MyDevMode As DEVMODE = Nothing PrinterName = PD.PrinterSettings.PrinterName If PrinterName = "" Then Exit Sub PrnD.pDatatype = Nothing PrnD.pDevMode = 0& PrnD.DesiredAccess = PRINTER_ALL_ACCESS Call OpenPrinter(PrinterName, PrinterHandle, PrnD) Call GetPrinter(PrinterHandle, 2, IntPtr.Zero, 0, Needed) 'メモリを割り当てる pPrinterInfo = Marshal.AllocHGlobal(Needed) Call GetPrinter(PrinterHandle, 2, pPrinterInfo, Needed, Needed) PrinterInfo = CType(Marshal.PtrToStructure( _ pPrinterInfo, GetType(PRINTER_INFO_2)), PRINTER_INFO_2) pFullDevMode = PrinterInfo.pDevMode '??? この辺りから? Call CopyMemory1(MyDevMode, pFullDevMode, Len(MyDevMode)) With MyDevMode .dmOrientation = DMORIENT_PORTAIT '縦向き .dmPaperSize = 256 .dmPaperLength = 4000 .dmPaperWidth = 2500 .dmFields = DM_PAPERSIZE Or DM_PAPERWIDTH Or DM_PAPERLENGTH End With Call CopyMemory2(pFullDevMode, MyDevMode, Len(MyDevMode)) Result = SetPrinter(PrinterHandle, 2, PrinterInfo, IntPtr.Zero) '??? /この辺りまで? Call ClosePrinter(PrinterHandle) Me.Cursor = Cursors.Default End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub End Class