Making function calls to a third-party printer SDK from VBA 
Author Message
 Making function calls to a third-party printer SDK from VBA

Hi All,

I have successfully captured the File->Print event message
from within MS Word by writing a macro using VBA.  In
place of the standard print dialog which is always
displayed whenever File->Print is clicked, I am now
displaying a customized dialog.  From this customized
dialog, I intend to make function calls to a third-party
printer SDK.  By making function calls to this printer
SDK, I will be able to customize various printing options
specific to the printer I am working with.  Does anyone
have any ideas as to how to make function calls to a third-
party printer SDK from within VBA?

Any help is greatly appreciated!
Nancy



Tue, 17 Aug 2004 04:12:24 GMT  
 Making function calls to a third-party printer SDK from VBA
Hi, Nancy,

First you'll need to get the headers or prototypes of the functions in the SDK. If these are
provided as C or C++ headers, which is likely, you will have to figure out which VB data types are
equivalent to the data types of the functions' arguments and return values. (This can sometimes be
quite difficult, especially if you need to pass structures.)

Once you get that figured out, you'll need to place a Declare statement at the top of your VBA
module for each SDK function, to tell VBA which DLL contains the code of the function, its Alias if
any, and the argument list and return type.

For the Win32 API, you can get a text file that lists the VB equivalents of all the functions
(win32api.txt, available at http://www.microsoft.com/officedev/o-free.htm). If you're really lucky,
the supplier of the third-party printer SDK has a similar file, but don't count on it.

--
Regards,
Jay Freedman
Microsoft Word MVP        Word MVP FAQ site: http://www.mvps.org/word


Quote:
> Hi All,

> I have successfully captured the File->Print event message
> from within MS Word by writing a macro using VBA.  In
> place of the standard print dialog which is always
> displayed whenever File->Print is clicked, I am now
> displaying a customized dialog.  From this customized
> dialog, I intend to make function calls to a third-party
> printer SDK.  By making function calls to this printer
> SDK, I will be able to customize various printing options
> specific to the printer I am working with.  Does anyone
> have any ideas as to how to make function calls to a third-
> party printer SDK from within VBA?

> Any help is greatly appreciated!
> Nancy



Tue, 17 Aug 2004 04:49:19 GMT  
 Making function calls to a third-party printer SDK from VBA
Hi, Jay,

Thank you for your response and input.  I am now trying
out Win32 API calls from within VBA.  In particular, I am
trying to call a Win32 API called "EnumPrinters"   I have
previously been successful in calling this API using C++.  
I am now basically trying to convert the following C++
code into VB.  Note that I am making two calls to
EnumPrinters, one after the other.  This is because the
first call to EnumPrinters will return a value into
dwSize, which is then used to initialize
pEnumPrinterBuffer which in turn is used in the second
call to EnumPrinters.  The problem I having is converting
this line of C++ code into VB:
 pEnumPrinterBuffer = new BYTE[dwSize];  
If you or anyone else knows how to do this conversion,
please let me know.  Thanks!
Nancy

p.s. I have included both my C++ and VB code below.

C++
-----------------------------------------------------------
---
BOOL bRet;                                      // Return
Values
DWORD   dwFlags = 0;                    // Printer object
types
DWORD   dwLevel = 0;                    // Information
level
DWORD   dwPrinterInfoNum = 0;  // Bytes received
DWORD   dwSize = 0;                 // Number of printers
enumerated
BYTE * pEnumPrinterBuffer;

bRet = EnumPrinters(dwFlags, NULL, dwLevel, NULL, 0,
&dwSize,
                &dwPrinterInfoNum);

        pEnumPrinterBuffer = new BYTE[dwSize];  //Need to
convert this line into VB, any ideas?

        bRet = EnumPrinters(dwFlags, NULL, dwLevel,
pEnumPrinterBuffer, dwSize, &dwSize,
                &dwPrinterInfoNum);
VB
-----------------------------------------------------------
---
Declare Function EnumPrinters Lib "winspool.drv"
Alias "EnumPrintersA" (ByVal flags As Long, ByVal name As
String, ByVal Level As Long, pPrinterEnum As Byte, ByVal
cdBuf As Long, pcbNeeded As Long, pcReturned As Long) As
Long

Public Const PRINTER_ENUM_CONNECTIONS = &H4
Public Const PRINTER_ENUM_LOCAL = &H2

Sub FilePrint()
'
' FilePrint Macro
' Prints the active document
Dim lRet As Long
Dim lFlags As Long
Dim lLevel As Long
Dim lPrinterInfoNum As Long
Dim lSize As Long
Dim tempByte As Byte

    lFlags = PRINTER_ENUM_CONNECTIONS And
PRINTER_ENUM_LOCAL
    lLevel = 4
    lSize = 0
    lRet = EnumPrinters(6, 0, lLevel, 0, 0, lSize,
lPrinterInfoNum)
    ???
    lRet = EnumPrinters(6, 0, lLevel, ???, lSize, lSize,
lPrinterInfoNum)

Quote:
>-----Original Message-----
>Hi, Nancy,

>First you'll need to get the headers or prototypes of the

functions in the SDK. If these are
Quote:
>provided as C or C++ headers, which is likely, you will

have to figure out which VB data types are
Quote:
>equivalent to the data types of the functions' arguments

and return values. (This can sometimes be
Quote:
>quite difficult, especially if you need to pass
structures.)

>Once you get that figured out, you'll need to place a

Declare statement at the top of your VBA
Quote:
>module for each SDK function, to tell VBA which DLL

contains the code of the function, its Alias if
Quote:
>any, and the argument list and return type.

>For the Win32 API, you can get a text file that lists the

VB equivalents of all the functions
Quote:
>(win32api.txt, available at

http://www.microsoft.com/officedev/o-free.htm). If you're
really lucky,
Quote:
>the supplier of the third-party printer SDK has a similar

file, but don't count on it.
Quote:

>--
>Regards,
>Jay Freedman
>Microsoft Word MVP        Word MVP FAQ site:

http://www.mvps.org/word
Quote:



>> Hi All,

>> I have successfully captured the File->Print event
message
>> from within MS Word by writing a macro using VBA.  In
>> place of the standard print dialog which is always
>> displayed whenever File->Print is clicked, I am now
>> displaying a customized dialog.  From this customized
>> dialog, I intend to make function calls to a third-party
>> printer SDK.  By making function calls to this printer
>> SDK, I will be able to customize various printing
options
>> specific to the printer I am working with.  Does anyone
>> have any ideas as to how to make function calls to a
third-
>> party printer SDK from within VBA?

>> Any help is greatly appreciated!
>> Nancy

>.



Wed, 18 Aug 2004 03:25:38 GMT  
 Making function calls to a third-party printer SDK from VBA
Hi, Nancy,

There's a complete macro at http://www.mvps.org/word/FAQs/MacrosVBA/AvailablePrinters.htm that shows
how to retrieve the list of printers with the EnumPrinters API. Comparing that code to yours, it
uses the VB operator ReDim to resize the buffer, rather than allocating a new buffer with a
different size. Since VB likes to pretend that it doesn't use pointers <g> I guess this works just
as well.

--
Regards,
Jay Freedman
Microsoft Word MVP        Word MVP FAQ site: http://www.mvps.org/word


Quote:
> Hi, Jay,

> Thank you for your response and input.  I am now trying
> out Win32 API calls from within VBA.  In particular, I am
> trying to call a Win32 API called "EnumPrinters"   I have
> previously been successful in calling this API using C++.
> I am now basically trying to convert the following C++
> code into VB.  Note that I am making two calls to
> EnumPrinters, one after the other.  This is because the
> first call to EnumPrinters will return a value into
> dwSize, which is then used to initialize
> pEnumPrinterBuffer which in turn is used in the second
> call to EnumPrinters.  The problem I having is converting
> this line of C++ code into VB:
>  pEnumPrinterBuffer = new BYTE[dwSize];
> If you or anyone else knows how to do this conversion,
> please let me know.  Thanks!
> Nancy

> p.s. I have included both my C++ and VB code below.

> C++
> -----------------------------------------------------------
> ---
> BOOL bRet;                 // Return
> Values
> DWORD dwFlags = 0;                 // Printer object
> types
> DWORD dwLevel = 0;                 // Information
> level
> DWORD dwPrinterInfoNum = 0;  // Bytes received
> DWORD dwSize = 0;     // Number of printers
> enumerated
> BYTE * pEnumPrinterBuffer;

> bRet = EnumPrinters(dwFlags, NULL, dwLevel, NULL, 0,
> &dwSize,
> &dwPrinterInfoNum);

> pEnumPrinterBuffer = new BYTE[dwSize];  //Need to
> convert this line into VB, any ideas?

> bRet = EnumPrinters(dwFlags, NULL, dwLevel,
> pEnumPrinterBuffer, dwSize, &dwSize,
> &dwPrinterInfoNum);
> VB
> -----------------------------------------------------------
> ---
> Declare Function EnumPrinters Lib "winspool.drv"
> Alias "EnumPrintersA" (ByVal flags As Long, ByVal name As
> String, ByVal Level As Long, pPrinterEnum As Byte, ByVal
> cdBuf As Long, pcbNeeded As Long, pcReturned As Long) As
> Long

> Public Const PRINTER_ENUM_CONNECTIONS = &H4
> Public Const PRINTER_ENUM_LOCAL = &H2

> Sub FilePrint()
> '
> ' FilePrint Macro
> ' Prints the active document
> Dim lRet As Long
> Dim lFlags As Long
> Dim lLevel As Long
> Dim lPrinterInfoNum As Long
> Dim lSize As Long
> Dim tempByte As Byte

>     lFlags = PRINTER_ENUM_CONNECTIONS And
> PRINTER_ENUM_LOCAL
>     lLevel = 4
>     lSize = 0
>     lRet = EnumPrinters(6, 0, lLevel, 0, 0, lSize,
> lPrinterInfoNum)
>     ???
>     lRet = EnumPrinters(6, 0, lLevel, ???, lSize, lSize,
> lPrinterInfoNum)

> >-----Original Message-----
> >Hi, Nancy,

> >First you'll need to get the headers or prototypes of the
> functions in the SDK. If these are
> >provided as C or C++ headers, which is likely, you will
> have to figure out which VB data types are
> >equivalent to the data types of the functions' arguments
> and return values. (This can sometimes be
> >quite difficult, especially if you need to pass
> structures.)

> >Once you get that figured out, you'll need to place a
> Declare statement at the top of your VBA
> >module for each SDK function, to tell VBA which DLL
> contains the code of the function, its Alias if
> >any, and the argument list and return type.

> >For the Win32 API, you can get a text file that lists the
> VB equivalents of all the functions
> >(win32api.txt, available at
> http://www.microsoft.com/officedev/o-free.htm). If you're
> really lucky,
> >the supplier of the third-party printer SDK has a similar
> file, but don't count on it.

> >--
> >Regards,
> >Jay Freedman
> >Microsoft Word MVP        Word MVP FAQ site:
> http://www.mvps.org/word



> >> Hi All,

> >> I have successfully captured the File->Print event
> message
> >> from within MS Word by writing a macro using VBA.  In
> >> place of the standard print dialog which is always
> >> displayed whenever File->Print is clicked, I am now
> >> displaying a customized dialog.  From this customized
> >> dialog, I intend to make function calls to a third-party
> >> printer SDK.  By making function calls to this printer
> >> SDK, I will be able to customize various printing
> options
> >> specific to the printer I am working with.  Does anyone
> >> have any ideas as to how to make function calls to a
> third-
> >> party printer SDK from within VBA?

> >> Any help is greatly appreciated!
> >> Nancy

> >.



Wed, 18 Aug 2004 03:58:51 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. VBA interface to third party DLL

2. VBScript calling third party dll

3. VB calling DLL using Third party .ocx

4. CALLING A THIRD PARTY 'EXE'

5. call a 16bit third party dll from VB5

6. A third party control called Spread OCX

7. Access95/VB/Windows SDK - Making API Calls...

8. Access functions in 3rd party VBA

9. Are there third party Command Button

10. Third Party Download Managers

11. Automatic Sending of Email by third party software (Access based)

12. Automatic Sending of Email by third party software (Access based)

 

 
Powered by phpBB® Forum Software