Hi there,
why would I receive the above error when I use CreateObject?
The following code works:
Dim obj as MyComObj
Set obj = New MyComObj
but if I use the following code it errors:
Dim obj
Set obj = CreateObject("MyComObj")
Dick Grier - 17 Jul 2008 16:37 GMT
Why are you using CreateObject? Is late-binding necessary? Is MyComObj the
name displayed in the ObjectBrowser?
This is one of those questions that requires more details, I think.

Signature
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.
Waldy - 17 Jul 2008 16:57 GMT
> Why are you using CreateObject?
Er, no particular reason. I am just trying to blow out the cobwebs and
create a C++ COM library. (It's been a while!). This was just to test that
I had created it correctly.
>Is late-binding necessary?
No. I just wanted to understand why it doesn't work.
> Is MyComObj the name displayed in the ObjectBrowser?#
No. That's something I made up for this post. I can see the object in the
object browser.
MikeD - 17 Jul 2008 19:23 GMT
> Hi there,
> why would I receive the above error when I use CreateObject?
[quoted text clipped - 10 lines]
>
> Set obj = CreateObject("MyComObj")
You've only provided half of the progid (the string you pass to CreateObject).
Using MS Word as an example:
Dim oWord As Object
Set oWord = CreateObject("Word.Application")
oWord.Visible = True
oWord.Quit
Set oWord = Nothing
Note the string "Word.Application"...2 parts to it separated by a period.

Signature
Mike
Microsoft Visual Basic MVP
Waldy - 18 Jul 2008 12:32 GMT
> You've only provided half of the progid (the string you pass to
> CreateObject).
As I stated in the previous post, that name was only for posting. I
actually used the "library.interface" name as shown in the object browser.
I was hoping that someone could tell me what was wrong with the COM object.
ie: I thought that it had to be Dual and IDispatch to work VB e.t.c.
Ralph - 29 Jul 2008 17:34 GMT
> Hi there,
> why would I receive the above error when I use CreateObject?
[quoted text clipped - 10 lines]
>
> Set obj = CreateObject("MyComObj")
While they are often spelled the same they are two totally different
identifiers.
"MyComObj" as used in:
Dim obj As MyComObj
Is an Interface ID as published with a Typelib.
"MyComObj" when used with CreateObject is a ProgID or AppID as defined in
the registry. If you examine the Registry you will see ProgID/AppIDs do
nothing more than redirect to a registered type.
While Library/Interface IDs are chiselled in stone by the component's
published Interface, ProgIDs can be anything the development tool decides.
C/C++ tools tend to use coclass::class by default, VB uses
library::Interface. Note again, they are often the same, but not always. In
fact you can go into the registry and create your own... As long as it
resolves to an existing component it will work fine.
Anyway, the latter is failing because you don't have a Registry entry for
that ProgID, or the entry value is invalid.
hth
-ralph