Autor Thema: API-Funktionen  (Gelesen 3969 mal)

Offline Demian

  • Gold Platin u.s.w. member:)
  • *****
  • Beiträge: 569
  • Geschlecht: Männlich
API-Funktionen
« am: 15.05.06 - 17:04:53 »
Hallo alle zusammen,

es ist mal wieder soweit. Ich habe für Excel ein Modul mit API-Funktionen zum Ändern der Druckerschächte.

Meine Frage ist nun, wie lässt sich das in Notes umsetzen?

Hier erst mal der Code:

Option Explicit

   Public Type PRINTER_DEFAULTS
       pDatatype As Long
       pDevmode As Long
       DesiredAccess As Long
   End Type

   Public Type PRINTER_INFO_2
       pServerName As Long
       pPrinterName As Long
       pShareName As Long
       pPortName As Long
       pDriverName As Long
       pComment As Long
       pLocation As Long
       pDevmode As Long       ' Pointer to DEVMODE
       pSepFile As Long
       pPrintProcessor As Long
       pDatatype As Long
       pParameters As Long
       pSecurityDescriptor As Long  ' Pointer to SECURITY_DESCRIPTOR
       Attributes As Long
       Priority As Long
       DefaultPriority As Long
       StartTime As Long
       UntilTime As Long
       Status As Long
       cJobs As Long
       AveragePPM As Long
   End Type

   Public Type DEVMODE
       dmDeviceName As String * 32
       dmSpecVersion As Integer
       dmDriverVersion As Integer
       dmSize As Integer
       dmDriverExtra As Integer
       dmFields As Long
       dmOrientation As Integer
       dmPaperSize As Integer
       dmPaperLength As Integer
       dmPaperWidth As Integer
       dmScale As Integer
       dmCopies As Integer
       dmDefaultSource As Integer
       dmPrintQuality As Integer
       dmColor As Integer
       dmDuplex As Integer
       dmYResolution As Integer
       dmTTOption As Integer
       dmCollate As Integer
       dmFormName As String * 32
       dmUnusedPadding As Integer
       dmBitsPerPel As Integer
       dmPelsWidth As Long
       dmPelsHeight As Long
       dmDisplayFlags As Long
       dmDisplayFrequency As Long
       dmICMMethod As Long
       dmICMIntent As Long
       dmMediaType As Long
       dmDitherType As Long
       dmReserved1 As Long
       dmReserved2 As Long
   End Type

   Public Const DM_DUPLEX = &H1000&
   Public Const DM_IN_BUFFER = 8

   Public Const DM_OUT_BUFFER = 2
   Public Const PRINTER_ACCESS_ADMINISTER = &H4
   Public Const PRINTER_ACCESS_USE = &H8
   Public Const STANDARD_RIGHTS_REQUIRED = &HF0000
   Public Const PRINTER_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or _
             PRINTER_ACCESS_ADMINISTER Or PRINTER_ACCESS_USE)

   Public Declare Function ClosePrinter Lib "winspool.drv" _
    (ByVal hPrinter As Long) As Long
   Public Declare Function DocumentProperties Lib "winspool.drv" _
     Alias "DocumentPropertiesA" (ByVal hwnd As Long, _
     ByVal hPrinter As Long, ByVal pDeviceName As String, _
     ByVal pDevModeOutput As Long, ByVal pDevModeInput As Long, _
     ByVal fMode As Long) As Long
   Public Declare Function GetPrinter Lib "winspool.drv" Alias _
     "GetPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, _
     pPrinter As Byte, ByVal cbBuf As Long, pcbNeeded As Long) As Long
   Public Declare Function OpenPrinter Lib "winspool.drv" Alias _
     "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, _
     pDefault As PRINTER_DEFAULTS) As Long
   Public Declare Function SetPrinter Lib "winspool.drv" Alias _
     "SetPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, _
     pPrinter As Byte, ByVal Command As Long) As Long

   Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
    (pDest As Any, pSource As Any, ByVal cbLength As Long)
 
   ' ==================================================================
   ' SetPrinterDuplex
   '
   '  Programmatically set the Duplex flag for the specified printer
   '  driver's default properties.
   '
   '  Returns: True on success, False on error. (An error will also

   '  display a message box. This is done for informational value
   '  only. You should modify the code to support better error
   '  handling in your production application.)
   '
   '  Parameters:
   '    sPrinterName - The name of the printer to be used.
   '
   '    nDuplexSetting - One of the following standard settings:
   '       1 = None
   '       2 = Duplex on long edge (book)
   '       3 = Duplex on short edge (legal)
   '
   ' ==================================================================
   Public Function SetPrinterDuplex(ByVal sPrinterName As String, _
       ByVal nDuplexSetting As Long) As Boolean

      Dim hPrinter As Long
      Dim pd As PRINTER_DEFAULTS
      Dim pinfo As PRINTER_INFO_2
      Dim dm As DEVMODE
   
      Dim yDevModeData() As Byte
      Dim yPInfoMemory() As Byte
      Dim nBytesNeeded As Long
      Dim nRet As Long, nJunk As Long
   
      On Error GoTo cleanup
   
      If (nDuplexSetting < 1) Or (nDuplexSetting > 3) Then
         MsgBox "Error: dwDuplexSetting is incorrect."
         Exit Function
      End If
     
      pd.DesiredAccess = PRINTER_ALL_ACCESS
      nRet = OpenPrinter(sPrinterName, hPrinter, pd)
      If (nRet = 0) Or (hPrinter = 0) Then
         If Err.LastDllError = 5 Then
            MsgBox "Access denied -- See the article for more info."
         Else
            MsgBox "Cannot open the printer specified " & _
              "(make sure the printer name is correct)."
         End If
         Exit Function
      End If
   
      nRet = DocumentProperties(0, hPrinter, sPrinterName, 0, 0, 0)
      If (nRet < 0) Then
         MsgBox "Cannot get the size of the DEVMODE structure."
         GoTo cleanup
      End If
   
      ReDim yDevModeData(nRet + 100) As Byte
      nRet = DocumentProperties(0, hPrinter, sPrinterName, _
                  VarPtr(yDevModeData(0)), 0, DM_OUT_BUFFER)
      If (nRet < 0) Then
         MsgBox "Cannot get the DEVMODE structure."
         GoTo cleanup
      End If
   
      Call CopyMemory(dm, yDevModeData(0), Len(dm))
   
      If Not CBool(dm.dmFields And DM_DUPLEX) Then
        MsgBox "You cannot modify the duplex flag for this printer " & _
               "because it does not support duplex or the driver " & _
               "does not support setting it from the Windows API."
         GoTo cleanup
      End If
   
      dm.dmDefaultSource = 262

      Call CopyMemory(yDevModeData(0), dm, Len(dm))

      Call GetPrinter(hPrinter, 2, 0, 0, nBytesNeeded)

      ReDim yPInfoMemory(nBytesNeeded + 100) As Byte

     
    Call CopyMemory(pinfo, yPInfoMemory(0), Len(pinfo))
      pinfo.pDevmode = VarPtr(yDevModeData(0))
      pinfo.pSecurityDescriptor = 0
    Call CopyMemory(yPInfoMemory(0), pinfo, Len(pinfo))

      nRet = SetPrinter(hPrinter, 2, yPInfoMemory(0), 0)
    ActiveSheet.PrintOut
   
    dm.dmDefaultSource = 263

      Call CopyMemory(yDevModeData(0), dm, Len(dm))

      Call GetPrinter(hPrinter, 2, 0, 0, nBytesNeeded)

      ReDim yPInfoMemory(nBytesNeeded + 100) As Byte

     
    Call CopyMemory(pinfo, yPInfoMemory(0), Len(pinfo))
      pinfo.pDevmode = VarPtr(yDevModeData(0))
      pinfo.pSecurityDescriptor = 0
    Call CopyMemory(yPInfoMemory(0), pinfo, Len(pinfo))

      nRet = SetPrinter(hPrinter, 2, yPInfoMemory(0), 0)

cleanup:
      If (hPrinter <> 0) Then Call ClosePrinter(hPrinter)

   End Function

   
   Sub test()
   SetPrinterDuplex "HP LaserJet 4200 Schacht 2", 1
   End Sub

Wo "Sub Test" und "Public Function SetPrinterDuplex" sowie die Konstanten hingehören, ist mir klar. Was mir nicht genau klar ist, wo die eigentlichen API-Funktionen beispielsweise in einem Agenten eingefügt werden müssen.

Bei der Forum Suche hat er mir zum Thema "API" oder "API in Notes" viele Beiträge angezeigt, von denen die wenigsten beim schnellen durchklicken wirklich etwas damit zu tun hatten.

Gruß
Demian
Gruß
Demian

Offline Untitled

  • Senior Mitglied
  • ****
  • Beiträge: 364
    • Musiker24.ch - Musiker und Bands finden
Re: API-Funktionen
« Antwort #1 am: 15.05.06 - 17:19:46 »
In den Teil "Declarations".

Du musst dann noch die Scope-Bezeichner (?) entfernen. Aus
Code
Public Declare Function ClosePrinter Lib "winspool.drv" _
    (ByVal hPrinter As Long) As Long

wird dann zum Beispiel
Code
Declare Function ClosePrinter Lib "winspool.drv" _
    (Byval hPrinter As Long) As Long

Notes setzt die Deklarationen aber, falls du es vergeigst, auch automatisch selbst in den richtigen Teil.

Moritz

Offline Demian

  • Gold Platin u.s.w. member:)
  • *****
  • Beiträge: 569
  • Geschlecht: Männlich
Re: API-Funktionen
« Antwort #2 am: 15.05.06 - 19:42:01 »
Hallo Moritz,

vielen Dank für deine schnelle Antwort. Funktioniert soweit, nur die Funktion "SetPrinter" ist komplett rot hinterlegt. Auch wenn ich die Zeilenumbrüche raushole.

Gruß
Demian
Gruß
Demian

Offline Untitled

  • Senior Mitglied
  • ****
  • Beiträge: 364
    • Musiker24.ch - Musiker und Bands finden
Re: API-Funktionen
« Antwort #3 am: 16.05.06 - 08:39:41 »
Das liegt am "Command". In LotusScript ist dies ein Schlüsselwort.

Du kannst die Parameternamen aber frei wählen. Also geht zum Beispiel auch "lCommand".

Warum eine Zeile rot dargestellt wird, erkennst du übrigens in der Combobox unterhalb des Codefensters.

Grüsse
Moritz

Offline Demian

  • Gold Platin u.s.w. member:)
  • *****
  • Beiträge: 569
  • Geschlecht: Männlich
Re: API-Funktionen
« Antwort #4 am: 16.05.06 - 08:47:13 »
Hallo Moritz,

vielen Dank. Dachte es gäbe nur das @Command, aber man lernt nie aus.
Ja, ich konnte nur in diesem Fall nicht viel mit der Beschreibung anfangen. API-Funktionen sind ja auch so ein Thema für sich. Und ich kann nicht von mir behaupten, dass ich alles verstehe. Nur am Umsetzen der API-Funktionen scheitert es meistens nicht  ;D


Gruß
Demian
Gruß
Demian

 

Impressum Atnotes.de  -  Powered by Syslords Solutions  -  Datenschutz