Seeing if a COM library (reference) is installed?

M

Maury Markowitz

I'm trying to find a way to know whether or not a COM library is installed on
the machine my Access app is running on. I call the same library via an AddIn
wrapper in Excel, where I loop through the AddIns and look at each one's
name. Is there something similar for Access? A list of libraries or
References or something like that?

Maury
 
D

Douglas J. Steele

See whether Tools | References (while you're in the VB Editor) is what
you're looking for.
 
M

Maury Markowitz

Douglas J. Steele said:
See whether Tools | References (while you're in the VB Editor) is what
you're looking for.

I need to do it in code. It's installed on 50% of the machines here, the
code needs to know if it's there or not.

Maury
 
D

Douglas J. Steele

Maury Markowitz said:
I need to do it in code. It's installed on 50% of the machines here, the
code needs to know if it's there or not.

Why not just try to register it? If it's already registered, no harm will
occur. If it fails, then it doesn't really matter whether or not it's
present on the machine: you won't be able to use it.

Best way is to use the DllRegisterServer API:

Declare Function DllRegisterServer Lib "<yourlib.dll>" () As Long

Const ERROR_SUCCESS = &H0

' To register your DLL (or OCX) use this function:
If DllRegisterServer = ERROR_SUCCESS Then
MsgBox "Registration Successful"
Else
MsgBox "Registration Unsuccessful"
End If
 
M

Maury Markowitz

Douglas J. Steele said:
Why not just try to register it?

I tried that... I used References.AddFromFile(...) and sure enough the
References tab then shows the lib being loaded.

But then I can't figure out how to instantate it. If you do...

set ref = New mylib.myclass

it works perfectly if it's already loaded, but the module won't compile at
all if the lib isn't loaded, so you can't get to the line right above where
it's registering it!
So then I tried...

set ref = CreateObject(mylib.myclass)

but that always returns a 429. I don't know why this would be, because the
New syntax works fine!

Maury
 
D

Douglas J. Steele

Maury Markowitz said:
I tried that... I used References.AddFromFile(...) and sure enough the
References tab then shows the lib being loaded.

But then I can't figure out how to instantate it. If you do...

set ref = New mylib.myclass

it works perfectly if it's already loaded, but the module won't compile at
all if the lib isn't loaded, so you can't get to the line right above
where
it's registering it!
So then I tried...

set ref = CreateObject(mylib.myclass)

but that always returns a 429. I don't know why this would be, because the
New syntax works fine!

Don't know whether it's a typo on your part, but you need

set ref = CreateObject("mylib.myclass")
 
M

Maury Markowitz

Douglas J. Steele said:
Don't know whether it's a typo on your part, but you need

set ref = CreateObject("mylib.myclass")

Odd, I must have cut from an uncompiled copy.

But there's good news here, everything is working! It's a bit difficult to
find what to look for in the register unless someone tells you the key, or
you do a lot of looking on your own, but once you get the key you're all set.

There is a bit of oddness here though. Lots of keys use.dot.notation but in
fact that's just ad-hoc. The real separtor is /, something that I didn't see
in any of the examples on the MS pages I visited. So there was a bit of
hunting around to figure out the right syntax.

Then to add to the confusion, the key name is often "", which is rendered as
"(default)" in regedt.

So basically the code was the easiest part, trying to figure out the syntax
took me a lot of trial and error. But it works, and now I can find the
object, register it, open an instance and call it. Very cool.

Maury
 

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