I want to use the AddPrinter api to create a printer.

I'm new to API so i'm not even sure if i'm on the right path to even using the function correctly. Right now, when i run the program and click on the button it will crash. My code is below.

Can somone help me out and possibly tell me how to use this api or give me some sort of an example. Thanks in advance.







Declare Function AddPrinter Lib "winspool.drv" Alias "AddPrinterA" (ByVal pName As String, ByVal Level As Long, pPrinter As Any) As Long

Public Type PRINTER_INFO_2
pServerName As String
pPrinterName As String
pShareName As String
pPortName As String
pDriverName As String
pComment As String
pLocation As String
pSepFile As String
pPrintProcessor As String
pDatatype As String
pParameters As String
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

Private Sub Command1_Click()
Dim ptrPrinter As Long
Dim returnvalue As Long
Dim PrtInfo As PRINTER_INFO_2
PrtInfo.pPrintProcessor = "winprint"
PrtInfo.pDatatype = "RAW"
PrtInfo.pPrinterName = "TGI Print Preview"
PrtInfo.pPortName = "LPT3"
PrtInfo.pDriverName = "HP LaserJet 5si"
PrtInfo.pComment = "Test de l'ajout"
ptrPrinter = VarPtr(PrtInfo)
returnvalue = AddPrinter("", 2, ptrPrinter)
End Sub