Declaring API function, causes Compile error

J

Jules

I'm attempting to use VB to provide a list of installed printers on a
users PC. The code is from a textbook and I get no errors whilst
writing it, but when it is run I get a COMPILE ERROR at the Declaring
API functions. The Compile Error is "Only comments may appear after
End Sub, End Funtion, or End Property. Might be too many hours sat in
front of a screen but I can't see it. (Using Windows and Office XP)

Code follows:-

'1st, declare constants

Public Const KEY_ENUMERATE_SUB_KEYS = &H8
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const SUCCESS = 0&

'2nd, declare custom data type

Type FileTime
dwLowDateTime As Long
dwhighDateTime As Long
End Type

'3rd, declare API functions
'**** Error hightlight the following text

Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias _
"RegOpenKeyExA" (ByVal hkey As Long, ByVal lpsubkey As String, _
ByVal ulOptions As Long, ByVal samDesired As Long, _
phkResult As Long) As Long

Declare Function regEnumKeyEx Lib "advapi32.dll" Alias _
"regEnumKeyExA" (ByVal hkey As Long, ByVal dwIndex As _
Long, ByVal lpname As String, lpcbName As Long, ByVal _
lpreserved As ong, ByVal lpClass As String, lpcbClass _
As Long, lpftLastWriteTime As FileName) As Long

Declare Function regCloseKey Lib "advapi32.dll" _
(ByVal hkey As Long) As Long
 
S

Steve Rindsberg

Instead of "Declare Function" use just "Function"



--
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
Apologies for the delayed response.
Just back from PowerPoint Live 2004
Had a great time, learned a lot
================================================
 
J

Jules

Thanks for the reply Steve,

If I take the Declare from the start of any of the lines, the code
goes red, LIB is highlighted from the line of code and I get another
error message saying "compile error: expected end of statement"
 
S

Steve Rindsberg

Thanks for the reply Steve,

If I take the Declare from the start of any of the lines, the code
goes red, LIB is highlighted from the line of code and I get another
error message saying "compile error: expected end of statement"

My mistake on that suggestion ... sorry. But when I changed this:

Declare Function regEnumKeyEx Lib "advapi32.dll" Alias _
"regEnumKeyExA" (ByVal hkey As Long, ByVal dwIndex As _
Long, ByVal lpname As String, lpcbName As Long, ByVal _
lpreserved As ong, ByVal lpClass As String, lpcbClass _
As Long, lpftLastWriteTime As FileName) As Long


To this, it compiles:

Declare Function regEnumKeyEx Lib "advapi32.dll" Alias _
"regEnumKeyExA" (ByVal hkey As Long, ByVal dwIndex As _
Long, ByVal lpname As String, lpcbName As Long, ByVal _
lpreserved As Long, ByVal lpClass As String, lpcbClass _
As Long, lpftLastWriteTime As FileName) As Long

lpreserved as LONG, not ONG ;-)
and lpftLastWriteTime as String (or whatever's appropriate in this case ... but
not FileName)
--
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
Apologies for the delayed response.
Just back from PowerPoint Live 2004
Had a great time, learned a lot
================================================
 
J

Jim Zeeb

Jules,
Do you have an example of the code that gets the list of printers?
I'm looking to do the same thing.

Thanks,
....jz
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top