GetPrinterData

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • news.usinor.com

    #1

    GetPrinterData


    Hi,

    I have some problems to use GetPrinterData Win32 API. I can't get the result
    of this API when the ValueName is a REG_SZ or a MULTI_REG_SZ.

    Can anybody help me ?

    Thanks,

    Delfim.

    this a part of my code :



    <DllImport("win spool.Drv", CharSet:=CharSe t.Ansi,
    EntryPoint:="Ge tPrinterDataA", _
    SetLastError:=T rue, ExactSpelling:= True, _
    CallingConventi on:=CallingConv ention.StdCall) > _
    Private Shared Function GetPrinterData( _
    ByVal hPrinter As IntPtr, _
    <MarshalAs(Unma nagedType.LPStr )> ByVal pValueName As String, _
    ByRef pType As Integer, _
    ByRef pData As IntPtr, _
    ByVal nSize As Integer, _
    ByRef pcbNeeded As Integer) As Integer
    End Function

    Public Function GetPrinterData( ByVal PrinterName As String, ByVal ValueName
    As String) As Object
    Dim hPrinter As IntPtr
    Dim pData As IntPtr = IntPtr.Zero
    Dim cBuf As Integer
    Dim pcbNeeded As Integer
    Dim pType As Integer
    Dim ret As Integer
    Dim oData As Object

    hPrinter = OpenPrinter(Pri nterName)
    ret = GetPrinterData( hPrinter, ValueName, pType, IntPtr.Zero, 0,
    pcbNeeded)
    If pcbNeeded <= 0 Then
    Throw (New System.Exceptio n("Unable to allocate memory"))
    End If

    pData = Marshal.AllocHG lobal(pcbNeeded )
    ret = GetPrinterData( hPrinter, ValueName, pType, pData, pcbNeeded, cBuf)
    If ret <> 0 Then
    Throw New Win32Exception( Marshal.GetLast Win32Error())
    End If

    Select Case pType
    Case REG_DWORD
    oData = pData.ToInt32

    Case REG_SZ
    oData = pData 'Marshal.PtrToS tringAuto(pData )

    Case Else
    oData = pData
    End Select

    ClosePrinter(hP rinter)

    Return oData
    End Function


Working...