Constructor problem 
Author Message
 Constructor problem

Hi,
 I am returning error from FinalConstruct,
 Final Constructer is getting  called 4 times when i create instance
 in VB.
 why & how to solve this problem.

In Server ATL:
Class TestError
{

HRESULT FinalContruct
{
     HRESULT hr=CoCreateInstance(............)   ;

        if( hr != S_OK)
                return Error((LPCSTR)bstrErrorDesc , dwordHelpContext,
                                    (LPCSTR)bstrHelpFile ,
GUID_NULL,0x80030004);

Quote:
}
};

In VB Client :
dim Obj as <Dll Name>.TestError
set Obj= new <Dll Name>.TestError


Sun, 27 Feb 2005 21:43:13 GMT  
 Constructor problem
You made me curious, so I did some debugging. It turns out that VB uses
CoCreateInstanceEx to create the component, passing four MULTI_QI
structures - for IUnknown, IPersistStreamInit, IPersistPropertyBag and
your main interface. CoCreateInstanceEx implementation in Ole32.dll
obtains IClassFactory for your class and calls CreateInstance on it. If
this succeeds, CoCreateInstanceEx then queries for those four interfaces
and everybody's happy. But if IClassFactory::CreateInstance fails,
CoCreateInstanceEx retries it once for each entry in MULTI_QI array.
Rather unreasonable, if you ask me.

I don't see any workarounds, short of changing the design. Is it really
so bad that there are four attempts at creating the object?
--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken


Quote:
> Hi,
>  I am returning error from FinalConstruct,
>  Final Constructer is getting  called 4 times when i create instance
>  in VB.
>  why & how to solve this problem.

> In Server ATL:
> Class TestError
> {

> HRESULT FinalContruct
> {
>      HRESULT hr=CoCreateInstance(............)   ;

>         if( hr != S_OK)
>                 return Error((LPCSTR)bstrErrorDesc , dwordHelpContext,
>                                     (LPCSTR)bstrHelpFile ,
> GUID_NULL,0x80030004);
> }

> };

> In VB Client :
> dim Obj as <Dll Name>.TestError
> set Obj= new <Dll Name>.TestError



Sun, 27 Feb 2005 22:46:15 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Error C2512 - No appropriate constructor problem

2. Inexplicable copy constructor problem with STL allocator

3. Constructor problem

4. template constructor problem

5. extension DLLs and constructors problem

6. deque constructor problem

7. deque constructor problem: VC++ 5.0

8. constructor that calls a constructor

9. Invoking another constructor within a constructor

10. Calling Default Constructor from another constructor

11. Call other constructor in a constructor

12. Can you call a default constructor from an overloaded constructor

 

 
Powered by phpBB® Forum Software