0% found this document useful (0 votes)
160 views

Get Printer Driver Directory

To a form, add a text box (Text1) and a command button (Command1) with the following code: GetPrinterDriverDirectory lib "winspool.drv" you can freely use this code in your own'applications, but you may not reproduce'or publish this code on any web site,'online service, or distribute as source'on any media without express permission.

Uploaded by

api-26494615
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
160 views

Get Printer Driver Directory

To a form, add a text box (Text1) and a command button (Command1) with the following code: GetPrinterDriverDirectory lib "winspool.drv" you can freely use this code in your own'applications, but you may not reproduce'or publish this code on any web site,'online service, or distribute as source'on any media without express permission.

Uploaded by

api-26494615
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

To a form, add a text box (Text1) and a command button (Command1) with the

following code:

--------------------------------------------------------------------------------

Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright �1996-2005 VBnet, Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
' applications, but you may not reproduce
' or publish this code on any web site,
' online service, or distribute as source
' on any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Private Declare Function GetPrinterDriverDirectory Lib "winspool.drv" _
Alias "GetPrinterDriverDirectoryA" _
(ByVal pName As String, _
ByVal pEnvironment As String, _
ByVal level As Long, _
ByVal pDriverDirectory As String, _
ByVal cbBuff As Long, _
pcbNeeded As Long) As Long

Private Sub Form_Load()

Command1.Caption = "GetPrinterDriverDirectory"

End Sub

Private Sub Command1_Click()

Dim level As Long


Dim cbBuff As Long
Dim pcbNeeded As Long
Dim pName As String
Dim pEnvironment As String
Dim pDriverDirectory As String

'initialization to determine size of buffer required


level = 1 'must be 1
cbBuff = 0 'must be 0 initially
pDriverDirectory = vbNullString 'must be null string initially

'string that specifies the name of the


'server on which the printer driver resides.
'If this parameter is vbNullString the
'local driver-directory path is retrieved.
pName = vbNullString

'string that specifies the environment


'(for example, "Windows NT x86", "Windows NT R4000",
'"Windows NT Alpha_AXP", or "Windows 4.0"). If
'this parameter is NULL, the current environment
'of the calling application and client machine
'(not of the destination application and print
'server) is used.
pEnvironment = vbNullString

'find out how large the buffer


'needs to be (pcbNeeded). Call will return 0.
If GetPrinterDriverDirectory(pName, _
pEnvironment, _
level, _
pDriverDirectory, _
cbBuff, _
pcbNeeded) = 0 Then

'create a buffer large enough for the


'string and a trailing null
pDriverDirectory = Space$(pcbNeeded)
cbBuff = Len(pDriverDirectory)

'call again. Success = 1


If GetPrinterDriverDirectory(pName, _
pEnvironment, _
level, _
pDriverDirectory, _
cbBuff, _
pcbNeeded) = 1 Then

'result
Text1.Text = Left$(pDriverDirectory, pcbNeeded)

End If 'GetPrinterDriverDirectory/2
End If 'GetPrinterDriverDirectory/1

End Sub

You might also like