Results 1 to 4 of 4

Thread: Urgent Problem With AddPrinter API

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2000
    Posts
    2

    Angry

    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

  2. #2
    Guest
    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)


  3. #3

    Thread Starter
    New Member
    Join Date
    May 2000
    Posts
    2

    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.

  4. #4
    Guest
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width