Why New works and CreateObject fails ??? 
Author Message
 Why New works and CreateObject fails ???

I have a very simple ATL COM server which I try to call from VB. If I use
New to instanciate the server it works fine but if I try to use CreateObject
than it always fails ? Why ? I need to register my component as a pooled
object in a COM+ app under W2K and call it possibly from other COM+
applications so I think I need to use CreateObject so that the COM+ context
will be attached to the object (I need IObjectConstruct as well) !

Christian



Sat, 03 Apr 2004 19:41:15 GMT  
 Why New works and CreateObject fails ???
If you use the ATL Wizard to create an object Xyz in a
project Abc, and keeps the default settings, it creates an
object that you can reference in VB as:

Dim Obj As ABCLib.Xyz
Set Obj = New ABCLib.Xyz

or

Dim Obj As ABCLib.Xyz
Set Obj = CreateObject ("ABC.Xyz")

Not very nice - note that "Lib" is missing from the ProgID.

There are four solutions for that annoyance:

a) Change the ProgID manually in the .rgs file and
recompile; (ABC.Xyz -> ABCLib.Xyz)

or

b) Change manually all references to ABCLib to ABC in
the .cpp, .h and .idl files (ABCLib -> ABC)

or

c) Change all references in your VB programs from
CreateObject("ABCLib.Xyz") to "ABC.Xyz" (maybe the
solution you will adopt)

or

d) When creating a new ATL Object, please change the
ProgId to the desired value (maybe ABCLib.Xyz to be equal
to your declaration) in the wizard before clicking OK.

HTH

Edson E. Watanabe

Quote:
>-----Original Message-----
>I have a very simple ATL COM server which I try to call
from VB. If I use
>New to instanciate the server it works fine but if I try
to use CreateObject
>than it always fails ? Why ?
...

>Christian



Sat, 03 Apr 2004 21:39:31 GMT  
 Why New works and CreateObject fails ???

say you try to create an object  "mClassPtr.mProgId"

Dim o as new mClassPtr.mProgId
mProgId.DoSomething()   works fine..

but when you do that,
Dim o as object   ' new mClassPtr.mProgId
set o = CreateObject("mClassPtr.mProgId")    <-- that fails, right!
mProgId.DoSomething()

That "Ptr" extension refers to a smart pointer.. So try that and it will
work

Dim o as object
set o = CreateObject("mClassPtr.mProgId")    <-- that fails, right!
set o = CreateObject("mClass.mProgId")    <-- that succeeds!
mProgId.DoSomething()

so simply remove "Ptr" extension from the class
OK?


Quote:
> I have a very simple ATL COM server which I try to call from VB. If I use
> New to instanciate the server it works fine but if I try to use
CreateObject
> than it always fails ? Why ? I need to register my component as a pooled
> object in a COM+ app under W2K and call it possibly from other COM+
> applications so I think I need to use CreateObject so that the COM+
context
> will be attached to the object (I need IObjectConstruct as well) !

> Christian



Sat, 03 Apr 2004 21:35:10 GMT  
 Why New works and CreateObject fails ???
The most aestetic solution is to fix the library name. It's ugly from
the very beginning (and I hate all-caps names!)...

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD

MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================



Quote:
> If you use the ATL Wizard to create an object Xyz in a
> project Abc, and keeps the default settings, it creates an
> object that you can reference in VB as:

> Dim Obj As ABCLib.Xyz
> Set Obj = New ABCLib.Xyz

> or

> Dim Obj As ABCLib.Xyz
> Set Obj = CreateObject ("ABC.Xyz")

> Not very nice - note that "Lib" is missing from the ProgID.

> There are four solutions for that annoyance:

> a) Change the ProgID manually in the .rgs file and
> recompile; (ABC.Xyz -> ABCLib.Xyz)

> or

> b) Change manually all references to ABCLib to ABC in
> the .cpp, .h and .idl files (ABCLib -> ABC)

> or

> c) Change all references in your VB programs from
> CreateObject("ABCLib.Xyz") to "ABC.Xyz" (maybe the
> solution you will adopt)

> or

> d) When creating a new ATL Object, please change the
> ProgId to the desired value (maybe ABCLib.Xyz to be equal
> to your declaration) in the wizard before clicking OK.

> HTH

> Edson E. Watanabe

> >-----Original Message-----
> >I have a very simple ATL COM server which I try to call
> from VB. If I use
> >New to instanciate the server it works fine but if I try
> to use CreateObject
> >than it always fails ? Why ?
> ...

> >Christian



Sun, 04 Apr 2004 06:32:34 GMT  
 Why New works and CreateObject fails ???
take a look at the VC++ .rgs file.  You might not be using the correct
string to create the object.  Object naming in VC++ is not as
straightforward as in VB.


Quote:
> I have a very simple ATL COM server which I try to call from VB. If I use
> New to instanciate the server it works fine but if I try to use
CreateObject
> than it always fails ? Why ? I need to register my component as a pooled
> object in a COM+ app under W2K and call it possibly from other COM+
> applications so I think I need to use CreateObject so that the COM+
context
> will be attached to the object (I need IObjectConstruct as well) !

> Christian



Sun, 04 Apr 2004 07:45:46 GMT  
 Why New works and CreateObject fails ???
If I remember right, ATL components get created with a version-specific
progid, i.e. "Server.Object.1" instead of "Server.Object". New won't care,
since it doesn't use the progid, but CreateObject will.


Quote:
> take a look at the VC++ .rgs file.  You might not be using the correct
> string to create the object.  Object naming in VC++ is not as
> straightforward as in VB.



> > I have a very simple ATL COM server which I try to call from VB. If I
use
> > New to instanciate the server it works fine but if I try to use
> CreateObject
> > than it always fails ? Why ? I need to register my component as a pooled
> > object in a COM+ app under W2K and call it possibly from other COM+
> > applications so I think I need to use CreateObject so that the COM+
> context
> > will be attached to the object (I need IObjectConstruct as well) !



Sun, 04 Apr 2004 22:49:23 GMT  
 Why New works and CreateObject fails ???
Thanks to all, I was using the wrong Progid indeed, using ABCLib instead of
ABC in the CreateObject. I chose solution b by the way ;-)

Christian



Quote:
> If you use the ATL Wizard to create an object Xyz in a
> project Abc, and keeps the default settings, it creates an
> object that you can reference in VB as:

> Dim Obj As ABCLib.Xyz
> Set Obj = New ABCLib.Xyz

> or

> Dim Obj As ABCLib.Xyz
> Set Obj = CreateObject ("ABC.Xyz")

> Not very nice - note that "Lib" is missing from the ProgID.

> There are four solutions for that annoyance:

> a) Change the ProgID manually in the .rgs file and
> recompile; (ABC.Xyz -> ABCLib.Xyz)

> or

> b) Change manually all references to ABCLib to ABC in
> the .cpp, .h and .idl files (ABCLib -> ABC)

> or

> c) Change all references in your VB programs from
> CreateObject("ABCLib.Xyz") to "ABC.Xyz" (maybe the
> solution you will adopt)

> or

> d) When creating a new ATL Object, please change the
> ProgId to the desired value (maybe ABCLib.Xyz to be equal
> to your declaration) in the wizard before clicking OK.

> HTH

> Edson E. Watanabe

> >-----Original Message-----
> >I have a very simple ATL COM server which I try to call
> from VB. If I use
> >New to instanciate the server it works fine but if I try
> to use CreateObject
> >than it always fails ? Why ?
> ...

> >Christian



Mon, 05 Apr 2004 02:04:31 GMT  
 Why New works and CreateObject fails ???
You use a ProgID when you know you need a specific _version_ of the
component. When you don't care about the version (which is in most of
the cases), you use the version-independent ProgID to get the latest
version. CreateObject will work with both as long as the RGS file lists
the CLSID under both (there was a bug in ATL 2.1 not listing the
CLSID under the version-independent ProgID AFAICR...).

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD

MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================


Quote:
> If I remember right, ATL components get created with a version-specific
> progid, i.e. "Server.Object.1" instead of "Server.Object". New won't care,
> since it doesn't use the progid, but CreateObject will.



> > take a look at the VC++ .rgs file.  You might not be using the correct
> > string to create the object.  Object naming in VC++ is not as
> > straightforward as in VB.



> > > I have a very simple ATL COM server which I try to call from VB. If I
> use
> > > New to instanciate the server it works fine but if I try to use
> > CreateObject
> > > than it always fails ? Why ? I need to register my component as a
pooled
> > > object in a COM+ app under W2K and call it possibly from other COM+
> > > applications so I think I need to use CreateObject so that the COM+
> > context
> > > will be attached to the object (I need IObjectConstruct as well) !



Mon, 05 Apr 2004 05:19:18 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Why CreateObject() fails in DevStudio Macro?

2. Why CreateObject() fails in DevStudio Macro?

3. malloc failed but calloc worked, why?

4. wsh: CreateObject fails with prefix...

5. VB activation: CreateObject Vs 'New' operator

6. CreateObject() calls File->New

7. CreateObject vs New

8. new vs. CreateObject

9. Why is this failing?

10. why does this if statement fail ?

11. Why the application failed to start?

12. why does fopen fail?

 

 
Powered by phpBB® Forum Software