After countless hours of experimenting and googling, I can really use some help with getting a piece of existing code to work in Office VBA7 64 bits,that worked fine on 32. Purpose is check printer status. I originally used this code, embedded it in my app. Get the Number of Waiting Jobs of a specified Printer on your network
To get this working I checked the defs on Pinvoke.net C++ defs on Pinvoke.net
I Adapted my defs with PtrSafe, and all compiles and runs fine on 64bits. I understand that IntPtr in Vb.net is 100% equivalent to LongPtr in VBA7. That is what I tried with various combinations.
But all I get is "0 jobs" from the enumjobs call, or crashes when I change the DLL call defs. I suspect that some of the parameter defs have to be adapted to Any or Longptr, but where to start?
The definitins that I use now:
Option Explicit
Declare PtrSafe Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" _
(ByVal pPrinterName As String, phPrinter As Long, pDefault As Any) As Long
Declare PtrSafe Function ClosePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
Declare PtrSafe Function EnumJobs Lib "winspool.drv" Alias "EnumJobsA" _
(ByVal hPrinter As Long, ByVal FirstJob As Long, ByVal NoJobs As Long, _
ByVal Level As Long, pJob As Any, ByVal cdBuf As Long, _
pcbNeeded As Long, pcReturned As Long) As Long
Declare PtrSafe Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" _
(Destination As Any, _
Source As Any, _
ByVal Length As Long)
Declare PtrSafe Function lstrcpy Lib "kernel32" Alias "lstrcpyA" _
(lpString1 As Any, _
lpString2 As Any) As Long
Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Type JOB_INFO_1
JobId As Long
pPrinterName As Long
pMachineName As Long
pUserName As Long
pDocument As Long
pDatatype As Long
pStatus As Long
Status As Long
Priority As Long
Position As Long
TotalPages As Long
PagesPrinted As Long
Submitted As SYSTEMTIME
End Type
Public Const JOB_STATUS_PAUSED = &H1
Public Const JOB_STATUS_ERROR = &H2
Public Const JOB_STATUS_DELETING = &H4
Public Const JOB_STATUS_SPOOLING = &H8
Public Const JOB_STATUS_PRINTING = &H10
Public Const JOB_STATUS_OFFLINE = &H20
Public Const JOB_STATUS_PAPEROUT = &H40
Public Const JOB_STATUS_PRINTED = &H80
Public Const JOB_STATUS_DELETED = &H100
Public Const JOB_STATUS_BLOCKED_DEVQ = &H200
Public Const JOB_STATUS_USER_INTERVENTION = &H400 ' Windows 95 Only
Public Const NO_PRIORITY = 0
Public Const MAX_PRIORITY = 99
Public Const MIN_PRIORITY = 1
Public Const DEF_PRIORITY = 1
Thanks in advance!!