-
I would like to add a printer with the addprinter api but:
Here is the declaration in C++:
HANDLE AddPrinter( LPTSTR pName, // pointer to server name
DWORD Level, // printer info. structure level
LPBYTE pPrinter // pointer to structure);
here is my declaration in VB:
Declare Function AddPrinter Lib "winspool.drv" Alias "AddPrinterA" (ByVal pName As String, ByVal Level As Long, pPrinter As any) As Long
I call the API like that, before I have fill in the Printer_Info_2 structure:
ReturnValue = AddPrinter("", 2, PrtInfo)
Return Value is a long, PrtInfo is a Printer_Info_2 structure.
But this API doesn't work at all, I think there is a problem with the pPrinter parametre but I'm not sure...
Does someone help me quick please???
Thank You
-
Because PrtInfo is a structure, when you pass it you're passing a pointer to the first item in the structure (I think), rather than a pointer to the structure of pointers. Try passing the address explicitly like
Dim ptrPrinter as long
ptrPrinter = ObjPtr(PrtInfo)
ReturnValue = AddPrinter("", 2, ptrPrinter)
-
I have tried to pass the address like you wrote it here but it seems that the ObjPtr() function doesn't accept my PrtInfo structure, when I Lauch the Api VB make a type mismatch error.
I'm almost sure you're right, I have to pass the address but
how can I do that if the ObjPtr() function doesn't work???
Thank You.
-
Sorry, It's one of these:
VarPtr - Returns the address of a variable.
VarPtrArray - Returns the address of an array.
StrPtr - Returns the address of the UNICODE string buffer.
VarPtrStringArray - Returns the address of an array of strings.
ObjPtr - Returns the pointer to the interface referenced by an object variable.
John