J
Jon Vaughan
I have been given some code examples for printer status monitoring from a
company. But they only have the code in vb or vc. im coding in vb.net and im
trying to convert from one to the other. The problem is that the code uses
the vb6 syntax of "as any" when declaring the api functions. But vb.net
doesnt support these. What im hoping is that someone who knows more than me
about vb.net and api calling can have a look and see whats going on.
The code is as follows :
Attribute VB_Name = "Module1"
'WIN32API
Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal
pPrinterName As String, _
phPrinter
As Long, _
ByVal
pDefault As Long) As Long
Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As
Long
Declare Function EnumPrinters Lib "winspool.drv" Alias "EnumPrintersA"
(ByVal Flags As Long, _
ByVal
pName As String, _
ByVal
Level As Long, _
pPrinterInfo
As Any, _
ByVal
cdBuf As Long, _
pcbNeeded
As Long, _
pcReturned
As Long) As Long
Declare Function EnumPrinterDrivers Lib "winspool.drv" Alias
"EnumPrinterDriversA" (ByVal pName As String, _
ByVal pEnvironment As String, _
ByVal Level As Long, _
pDriverInfo As Any, _
ByVal cdBuf As Long, _
pcbNeeded As Long, _
pcRetruned As Long) As Long
Declare Sub MoveMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Destination
As Any, _
Source As
Any, _
ByVal
Length As Long)
Declare Function lstrcpy Lib "kernel32.dll" Alias "lstrcpyA" (lpString1 As
Any, _
lpString2 As
Any) As Long
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
pSepFile As Long
pPrintProcessor As Long
pDatatype As Long
pParameters As Long
pSecurityDescriptor As Long
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 DRIVER_INFO_3
cVersion As Long
pName As Long
pEnvironment As Long
pDriverPath As Long
pDataFile As Long
pConfigFile As Long
pHelpFile As Long
pDependentFiles As Long
pMonitorName As Long
pDefaultDataType As Long
End Type
Public Const INVALID_HANDLE_VALUE = -1
Public Const PRINTER_ENUM_LOCAL = &H2
'SMJSMON.DLL
Declare Function SMJSMonGetStatus Lib "SMJSMon" (ByVal hPrinter As Long, _
lpBuffer As Byte, _
ByVal dwNumberOfBytesToRead
As Long, _
lpdwNumberOfBytesRead As
Long) As Long
Declare Function SMJSMonGetStatusEx Lib "SMJSMon" (ByVal hPrinter As Long, _
lpBuffer As Byte, _
ByVal
dwNumberOfBytesToRead As Long, _
lpdwNumberOfBytesRead As
Long) As Long
The calling code that is giving the error is as follows :
MoveMemory(PrinterInfo(0), byPrinterInfoBuffer(0), Len(PrinterInfo(0)) *
nPrinterInfoReturned)
Printer info being defined earlier as :
Dim PrinterInfo() As PRINTER_INFO_2
As PrinterInfo(0) is accessing
Dim pServerName As Integer
from the PRINTER_INFO_2 structure, So I changed the function as follows
Declare Sub MoveMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Destination
As integer, _
Source As
Byte, _
ByVal
Length As Long)
But the error I get is Value of type 'Project1.Module1.PRINTER_INFO_2'
cannot be converted to 'Integer'."
Does anyone have an idea what is going on ? or where I can start to solve
this problem ?
Thanks
company. But they only have the code in vb or vc. im coding in vb.net and im
trying to convert from one to the other. The problem is that the code uses
the vb6 syntax of "as any" when declaring the api functions. But vb.net
doesnt support these. What im hoping is that someone who knows more than me
about vb.net and api calling can have a look and see whats going on.
The code is as follows :
Attribute VB_Name = "Module1"
'WIN32API
Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal
pPrinterName As String, _
phPrinter
As Long, _
ByVal
pDefault As Long) As Long
Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As
Long
Declare Function EnumPrinters Lib "winspool.drv" Alias "EnumPrintersA"
(ByVal Flags As Long, _
ByVal
pName As String, _
ByVal
Level As Long, _
pPrinterInfo
As Any, _
ByVal
cdBuf As Long, _
pcbNeeded
As Long, _
pcReturned
As Long) As Long
Declare Function EnumPrinterDrivers Lib "winspool.drv" Alias
"EnumPrinterDriversA" (ByVal pName As String, _
ByVal pEnvironment As String, _
ByVal Level As Long, _
pDriverInfo As Any, _
ByVal cdBuf As Long, _
pcbNeeded As Long, _
pcRetruned As Long) As Long
Declare Sub MoveMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Destination
As Any, _
Source As
Any, _
ByVal
Length As Long)
Declare Function lstrcpy Lib "kernel32.dll" Alias "lstrcpyA" (lpString1 As
Any, _
lpString2 As
Any) As Long
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
pSepFile As Long
pPrintProcessor As Long
pDatatype As Long
pParameters As Long
pSecurityDescriptor As Long
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 DRIVER_INFO_3
cVersion As Long
pName As Long
pEnvironment As Long
pDriverPath As Long
pDataFile As Long
pConfigFile As Long
pHelpFile As Long
pDependentFiles As Long
pMonitorName As Long
pDefaultDataType As Long
End Type
Public Const INVALID_HANDLE_VALUE = -1
Public Const PRINTER_ENUM_LOCAL = &H2
'SMJSMON.DLL
Declare Function SMJSMonGetStatus Lib "SMJSMon" (ByVal hPrinter As Long, _
lpBuffer As Byte, _
ByVal dwNumberOfBytesToRead
As Long, _
lpdwNumberOfBytesRead As
Long) As Long
Declare Function SMJSMonGetStatusEx Lib "SMJSMon" (ByVal hPrinter As Long, _
lpBuffer As Byte, _
ByVal
dwNumberOfBytesToRead As Long, _
lpdwNumberOfBytesRead As
Long) As Long
The calling code that is giving the error is as follows :
MoveMemory(PrinterInfo(0), byPrinterInfoBuffer(0), Len(PrinterInfo(0)) *
nPrinterInfoReturned)
Printer info being defined earlier as :
Dim PrinterInfo() As PRINTER_INFO_2
As PrinterInfo(0) is accessing
Dim pServerName As Integer
from the PRINTER_INFO_2 structure, So I changed the function as follows
Declare Sub MoveMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Destination
As integer, _
Source As
Byte, _
ByVal
Length As Long)
But the error I get is Value of type 'Project1.Module1.PRINTER_INFO_2'
cannot be converted to 'Integer'."
Does anyone have an idea what is going on ? or where I can start to solve
this problem ?
Thanks