passing com/atl object in vb 
Author Message
 passing com/atl object in vb

created an atl object w/various interfaces in idl/c++.  standard vb exe sees
it and uses it fine.  from the standard exe i pass it to an active x ocx
that i created in vb.  that works fine, too.  then, from the standard exe
i pass it to an active x exe that i made in vb - it crashes.  the function
i pass it to is empty - simply using the object as an argument causes the
crash.  however, i can pass a property of the object w/o any problems.  the
help file is for error 440 regarding automation errors, and is sufficiently
vague to be of no use.  any ideas?

this function is in the active x exe:

Public Function SetSpectraInfo(SpecClass As MyCoClass) As Boolean
    'crashes
    SetSpectraInfo = True
End Function

Public Function SetSpectraInfo(<MyCoClass.Property> As long) As Boolean
    'works fine
    SetSpectraInfo = True
End Function



Sat, 31 Jan 2004 22:11:36 GMT  
 passing com/atl object in vb
Hi Steve,

As I can see, there is a problem with interface marshalling of your ATL
component. It works fine when the component is accessed from the same
apartment where it was created (Standard EXE and OCX), but when you pass the
interface pointer to another process, COM fails to create a proxy/stub pair.

From your description, it is not clear, what crashes - client or server
process and how does it crashes ? What activation, threading models and
marshalling options does your ATL component support ? You could also post an
IDL of the interface that you are attempting to marshal.

Regards,
Dmitriy Zakharov.
Brainbench MVP for Visual Basic
http://www.brainbench.com


Quote:
> created an atl object w/various interfaces in idl/c++.  standard vb exe
sees
> it and uses it fine.  from the standard exe i pass it to an active x ocx
> that i created in vb.  that works fine, too.  then, from the standard exe
> i pass it to an active x exe that i made in vb - it crashes.  the function
> i pass it to is empty - simply using the object as an argument causes the
> crash.  however, i can pass a property of the object w/o any problems.
the
> help file is for error 440 regarding automation errors, and is
sufficiently
> vague to be of no use.  any ideas?

> this function is in the active x exe:

> Public Function SetSpectraInfo(SpecClass As MyCoClass) As Boolean
>     'crashes
>     SetSpectraInfo = True
> End Function

> Public Function SetSpectraInfo(<MyCoClass.Property> As long) As Boolean
>     'works fine
>     SetSpectraInfo = True
> End Function



Sun, 01 Feb 2004 17:12:37 GMT  
 passing com/atl object in vb
Hi Steve,

The problem is with your custom interfaces. COM does not marshal them
automatically and you need to compile and register the marshalling DLL if
you want to pass custom interface into another apartment. COM has a standard
marshalling code for IDispatch so dual interfaces can do without a
marshalling DLL. Your interfaces seem to return an HRESULT and use
Automation-compatible types, so why not to declare them as dual and use
automatic marshalling ? You may want to use IDispatchImpl template that
adds IDispatch implementation to your class.

Regards,
Dmitriy Zakharov.
Brainbench MVP for Visual Basic
http://www.brainbench.com


Quote:


> > Hi Steve,

> > As I can see, there is a problem with interface marshalling of your ATL
> > component. It works fine when the component is accessed from the same
> > apartment where it was created (Standard EXE and OCX), but when you pass
> the
> > interface pointer to another process, COM fails to create a proxy/stub
> pair.

> > From your description, it is not clear, what crashes - client or server
> > process and how does it crashes ?

> on the client side i get a msgbox that says
>             "Run-time error '-2147467259 (800004005)'
>             Method '<my vb method>' of object '_<my vb active x exe>'
failed

> What activation, threading models and
> > marshalling options does your ATL component support ?

> alas, i'm an atl newbie, so i don't know.  i looked through the project
> settings but didn't see anything that described these options.  however,
in
> the header file for my coclass i found the following:

>     class ATL_NO_VTABLE CCoWrapper :
>         public Asit,
>         public CComObjectRootEx<CComSingleThreadModel>,
>         public CComCoClass<CCoWrapper, &CLSID_CoWrapper>,
>         public IManage,
>         public IInfo,
>         public IProcess

> so it appears as though it's single threaded.

> i found some stuff on marshalling in the .h and _p.c files but have no
idea
> what they mean.  where do i find this info?

> You could also post an
> > IDL of the interface that you are attempting to marshal.

> the idl file is attached.

> i'm highly suspicous that this is because the active x ocx is in process
but
> the active x exe is out of process.

> thanks.

> > Regards,
> > Dmitriy Zakharov.
> > Brainbench MVP for Visual Basic
> > http://www.brainbench.com



> > > created an atl object w/various interfaces in idl/c++.  standard vb
exe
> > sees
> > > it and uses it fine.  from the standard exe i pass it to an active x
ocx
> > > that i created in vb.  that works fine, too.  then, from the standard
> exe
> > > i pass it to an active x exe that i made in vb - it crashes.  the
> function
> > > i pass it to is empty - simply using the object as an argument causes
> the
> > > crash.  however, i can pass a property of the object w/o any problems.
> > the
> > > help file is for error 440 regarding automation errors, and is
> > sufficiently
> > > vague to be of no use.  any ideas?

> > > this function is in the active x exe:

> > > Public Function SetSpectraInfo(SpecClass As MyCoClass) As Boolean
> > >     'crashes
> > >     SetSpectraInfo = True
> > > End Function

> > > Public Function SetSpectraInfo(<MyCoClass.Property> As long) As
Boolean
> > >     'works fine
> > >     SetSpectraInfo = True
> > > End Function



Mon, 02 Feb 2004 03:16:53 GMT  
 passing com/atl object in vb

Quote:
> Hi Steve,

> The problem is with your custom interfaces. COM does not marshal them
> automatically and you need to compile and register the marshalling DLL if
> you want to pass custom interface into another apartment. COM has a
standard
> marshalling code for IDispatch so dual interfaces can do without a
> marshalling DLL. Your interfaces seem to return an HRESULT and use
> Automation-compatible types

yes, i spent a fair amount of time learning what they were (BSTR,
SAFEARRAY...) and how to convert them to and from standard C/C++ types.

so why not to declare them as dual and use

Quote:
> automatic marshalling ?

'cuz i don't know what that means!  lol... but i guess i'll be learning it
in the next few days.

You may want to use IDispatchImpl template that

Quote:
> adds IDispatch implementation to your class.

hmmm... don't know anything about IDispatch yet, either, but i guess i'm
going to learn!  lol again...

i had run across a couple of things that gave me the sneaking suspicion that
IDispatch might help but hadn't had the time to look into it yet.  thanks,
i'll check it out.  i figure if i can make it work and understand your reply
i'll be ok.  so far all your reply means to me is "teach yourself about
IDispatch, teach yourself about dual interfaces, teach yourself about
marshalling", but hopefully in a couple of days it'll mean more.  i'm using
troelson's book - it seems pretty good.  hopefully what i need is in there
and msdn.

thanks again.



Mon, 02 Feb 2004 04:49:57 GMT  
 passing com/atl object in vb
Or alternatively put [oleautomation] which will make use of the
IDispatch marshaler without forcing you to make your interface
dual - sort of eating your cake and keeping it too :). Your interface
has the same restrictions as a dual interface - all method arguments
must use Automation-compatible types. the advantage is your
objects may implement multiple non-dual interafces while only
one dual interface may be implemented on an onject. The code
size is smaller too.

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

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


Quote:
> Hi Steve,

> The problem is with your custom interfaces. COM does not marshal them
> automatically and you need to compile and register the marshalling DLL if
> you want to pass custom interface into another apartment. COM has a
standard
> marshalling code for IDispatch so dual interfaces can do without a
> marshalling DLL. Your interfaces seem to return an HRESULT and use
> Automation-compatible types, so why not to declare them as dual and use
> automatic marshalling ? You may want to use IDispatchImpl template that
> adds IDispatch implementation to your class.

> Regards,
> Dmitriy Zakharov.
> Brainbench MVP for Visual Basic
> http://www.brainbench.com





> > > Hi Steve,

> > > As I can see, there is a problem with interface marshalling of your
ATL
> > > component. It works fine when the component is accessed from the same
> > > apartment where it was created (Standard EXE and OCX), but when you
pass
> > the
> > > interface pointer to another process, COM fails to create a proxy/stub
> > pair.

> > > From your description, it is not clear, what crashes - client or
server
> > > process and how does it crashes ?

> > on the client side i get a msgbox that says
> >             "Run-time error '-2147467259 (800004005)'
> >             Method '<my vb method>' of object '_<my vb active x exe>'
> failed

> > What activation, threading models and
> > > marshalling options does your ATL component support ?

> > alas, i'm an atl newbie, so i don't know.  i looked through the project
> > settings but didn't see anything that described these options.  however,
> in
> > the header file for my coclass i found the following:

> >     class ATL_NO_VTABLE CCoWrapper :
> >         public Asit,
> >         public CComObjectRootEx<CComSingleThreadModel>,
> >         public CComCoClass<CCoWrapper, &CLSID_CoWrapper>,
> >         public IManage,
> >         public IInfo,
> >         public IProcess

> > so it appears as though it's single threaded.

> > i found some stuff on marshalling in the .h and _p.c files but have no
> idea
> > what they mean.  where do i find this info?

> > You could also post an
> > > IDL of the interface that you are attempting to marshal.

> > the idl file is attached.

> > i'm highly suspicous that this is because the active x ocx is in process
> but
> > the active x exe is out of process.

> > thanks.

> > > Regards,
> > > Dmitriy Zakharov.
> > > Brainbench MVP for Visual Basic
> > > http://www.brainbench.com



> > > > created an atl object w/various interfaces in idl/c++.  standard vb
> exe
> > > sees
> > > > it and uses it fine.  from the standard exe i pass it to an active x
> ocx
> > > > that i created in vb.  that works fine, too.  then, from the
standard
> > exe
> > > > i pass it to an active x exe that i made in vb - it crashes.  the
> > function
> > > > i pass it to is empty - simply using the object as an argument
causes
> > the
> > > > crash.  however, i can pass a property of the object w/o any
problems.
> > > the
> > > > help file is for error 440 regarding automation errors, and is
> > > sufficiently
> > > > vague to be of no use.  any ideas?

> > > > this function is in the active x exe:

> > > > Public Function SetSpectraInfo(SpecClass As MyCoClass) As Boolean
> > > >     'crashes
> > > >     SetSpectraInfo = True
> > > > End Function

> > > > Public Function SetSpectraInfo(<MyCoClass.Property> As long) As
> Boolean
> > > >     'works fine
> > > >     SetSpectraInfo = True
> > > > End Function



Mon, 02 Feb 2004 08:22:01 GMT  
 passing com/atl object in vb
thanks, gentlemen.  i'm looking into both suggestions.

the [oleautomation] solution works except for one property i have which
takes a parameter (structure) which is not automation-compliant.  is it
possible to encapsulate it in a variant or some other automation-compliant
variable?  the structure is defined in the idl file so that clients can
declare a variable of that type and pass it in as an argument.  the elements
of the structure are then set and the client gets the correct values when
the function returns.  the individual elements of the structure are
automation-compliant (BSTR, long int).

IDispatch is going to take me a few days to understand, but i'm working on
it.


Quote:
> Or alternatively put [oleautomation] which will make use of the
> IDispatch marshaler without forcing you to make your interface
> dual - sort of eating your cake and keeping it too :). Your interface
> has the same restrictions as a dual interface - all method arguments
> must use Automation-compatible types. the advantage is your
> objects may implement multiple non-dual interafces while only
> one dual interface may be implemented on an onject. The code
> size is smaller too.

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

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



> > Hi Steve,

> > The problem is with your custom interfaces. COM does not marshal them
> > automatically and you need to compile and register the marshalling DLL
if
> > you want to pass custom interface into another apartment. COM has a
> standard
> > marshalling code for IDispatch so dual interfaces can do without a
> > marshalling DLL. Your interfaces seem to return an HRESULT and use
> > Automation-compatible types, so why not to declare them as dual and use
> > automatic marshalling ? You may want to use IDispatchImpl template that
> > adds IDispatch implementation to your class.

> > Regards,
> > Dmitriy Zakharov.
> > Brainbench MVP for Visual Basic
> > http://www.brainbench.com





> > > > Hi Steve,

> > > > As I can see, there is a problem with interface marshalling of your
> ATL
> > > > component. It works fine when the component is accessed from the
same
> > > > apartment where it was created (Standard EXE and OCX), but when you
> pass
> > > the
> > > > interface pointer to another process, COM fails to create a
proxy/stub
> > > pair.

> > > > From your description, it is not clear, what crashes - client or
> server
> > > > process and how does it crashes ?

> > > on the client side i get a msgbox that says
> > >             "Run-time error '-2147467259 (800004005)'
> > >             Method '<my vb method>' of object '_<my vb active x exe>'
> > failed

> > > What activation, threading models and
> > > > marshalling options does your ATL component support ?

> > > alas, i'm an atl newbie, so i don't know.  i looked through the
project
> > > settings but didn't see anything that described these options.
however,
> > in
> > > the header file for my coclass i found the following:

> > >     class ATL_NO_VTABLE CCoWrapper :
> > >         public Asit,
> > >         public CComObjectRootEx<CComSingleThreadModel>,
> > >         public CComCoClass<CCoWrapper, &CLSID_CoWrapper>,
> > >         public IManage,
> > >         public IInfo,
> > >         public IProcess

> > > so it appears as though it's single threaded.

> > > i found some stuff on marshalling in the .h and _p.c files but have no
> > idea
> > > what they mean.  where do i find this info?

> > > You could also post an
> > > > IDL of the interface that you are attempting to marshal.

> > > the idl file is attached.

> > > i'm highly suspicous that this is because the active x ocx is in
process
> > but
> > > the active x exe is out of process.

> > > thanks.

> > > > Regards,
> > > > Dmitriy Zakharov.
> > > > Brainbench MVP for Visual Basic
> > > > http://www.brainbench.com



> > > > > created an atl object w/various interfaces in idl/c++.  standard
vb
> > exe
> > > > sees
> > > > > it and uses it fine.  from the standard exe i pass it to an active
x
> > ocx
> > > > > that i created in vb.  that works fine, too.  then, from the
> standard
> > > exe
> > > > > i pass it to an active x exe that i made in vb - it crashes.  the
> > > function
> > > > > i pass it to is empty - simply using the object as an argument
> causes
> > > the
> > > > > crash.  however, i can pass a property of the object w/o any
> problems.
> > > > the
> > > > > help file is for error 440 regarding automation errors, and is
> > > > sufficiently
> > > > > vague to be of no use.  any ideas?

> > > > > this function is in the active x exe:

> > > > > Public Function SetSpectraInfo(SpecClass As MyCoClass) As Boolean
> > > > >     'crashes
> > > > >     SetSpectraInfo = True
> > > > > End Function

> > > > > Public Function SetSpectraInfo(<MyCoClass.Property> As long) As
> > Boolean
> > > > >     'works fine
> > > > >     SetSpectraInfo = True
> > > > > End Function



Mon, 02 Feb 2004 22:12:05 GMT  
 passing com/atl object in vb
See item 4 in the COM/ATL FAQ in my signature. Basically, all you
have to do is make your strcuct Automation friendly by assigning
it a GUID (don't use typedef to avoid a common mistake) and
passing it always via a pointer (never on the stack). You said
the types in it are already Auitomation types. Note: don't use
INT as VB won't understand it. Use LONG instead. (See item 6)

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

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


Quote:
> thanks, gentlemen.  i'm looking into both suggestions.

> the [oleautomation] solution works except for one property i have which
> takes a parameter (structure) which is not automation-compliant.  is it
> possible to encapsulate it in a variant or some other automation-compliant
> variable?  the structure is defined in the idl file so that clients can
> declare a variable of that type and pass it in as an argument.  the
elements
> of the structure are then set and the client gets the correct values when
> the function returns.  the individual elements of the structure are
> automation-compliant (BSTR, long int).

> IDispatch is going to take me a few days to understand, but i'm working on
> it.



> > Or alternatively put [oleautomation] which will make use of the
> > IDispatch marshaler without forcing you to make your interface
> > dual - sort of eating your cake and keeping it too :). Your interface
> > has the same restrictions as a dual interface - all method arguments
> > must use Automation-compatible types. the advantage is your
> > objects may implement multiple non-dual interafces while only
> > one dual interface may be implemented on an onject. The code
> > size is smaller too.

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

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



> > > Hi Steve,

> > > The problem is with your custom interfaces. COM does not marshal them
> > > automatically and you need to compile and register the marshalling DLL
> if
> > > you want to pass custom interface into another apartment. COM has a
> > standard
> > > marshalling code for IDispatch so dual interfaces can do without a
> > > marshalling DLL. Your interfaces seem to return an HRESULT and use
> > > Automation-compatible types, so why not to declare them as dual and
use
> > > automatic marshalling ? You may want to use IDispatchImpl template
that
> > > adds IDispatch implementation to your class.

> > > Regards,
> > > Dmitriy Zakharov.
> > > Brainbench MVP for Visual Basic
> > > http://www.brainbench.com





> > > > > Hi Steve,

> > > > > As I can see, there is a problem with interface marshalling of
your
> > ATL
> > > > > component. It works fine when the component is accessed from the
> same
> > > > > apartment where it was created (Standard EXE and OCX), but when
you
> > pass
> > > > the
> > > > > interface pointer to another process, COM fails to create a
> proxy/stub
> > > > pair.

> > > > > From your description, it is not clear, what crashes - client or
> > server
> > > > > process and how does it crashes ?

> > > > on the client side i get a msgbox that says
> > > >             "Run-time error '-2147467259 (800004005)'
> > > >             Method '<my vb method>' of object '_<my vb active x
exe>'
> > > failed

> > > > What activation, threading models and
> > > > > marshalling options does your ATL component support ?

> > > > alas, i'm an atl newbie, so i don't know.  i looked through the
> project
> > > > settings but didn't see anything that described these options.
> however,
> > > in
> > > > the header file for my coclass i found the following:

> > > >     class ATL_NO_VTABLE CCoWrapper :
> > > >         public Asit,
> > > >         public CComObjectRootEx<CComSingleThreadModel>,
> > > >         public CComCoClass<CCoWrapper, &CLSID_CoWrapper>,
> > > >         public IManage,
> > > >         public IInfo,
> > > >         public IProcess

> > > > so it appears as though it's single threaded.

> > > > i found some stuff on marshalling in the .h and _p.c files but have
no
> > > idea
> > > > what they mean.  where do i find this info?

> > > > You could also post an
> > > > > IDL of the interface that you are attempting to marshal.

> > > > the idl file is attached.

> > > > i'm highly suspicous that this is because the active x ocx is in
> process
> > > but
> > > > the active x exe is out of process.

> > > > thanks.

> > > > > Regards,
> > > > > Dmitriy Zakharov.
> > > > > Brainbench MVP for Visual Basic
> > > > > http://www.brainbench.com



> > > > > > created an atl object w/various interfaces in idl/c++.  standard
> vb
> > > exe
> > > > > sees
> > > > > > it and uses it fine.  from the standard exe i pass it to an
active
> x
> > > ocx
> > > > > > that i created in vb.  that works fine, too.  then, from the
> > standard
> > > > exe
> > > > > > i pass it to an active x exe that i made in vb - it crashes.
the
> > > > function
> > > > > > i pass it to is empty - simply using the object as an argument
> > causes
> > > > the
> > > > > > crash.  however, i can pass a property of the object w/o any
> > problems.
> > > > > the
> > > > > > help file is for error 440 regarding automation errors, and is
> > > > > sufficiently
> > > > > > vague to be of no use.  any ideas?

> > > > > > this function is in the active x exe:

> > > > > > Public Function SetSpectraInfo(SpecClass As MyCoClass) As
Boolean
> > > > > >     'crashes
> > > > > >     SetSpectraInfo = True
> > > > > > End Function

> > > > > > Public Function SetSpectraInfo(<MyCoClass.Property> As long) As
> > > Boolean
> > > > > >     'works fine
> > > > > >     SetSpectraInfo = True
> > > > > > End Function



Tue, 03 Feb 2004 01:51:08 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Bitmap in VB -> ATL COM object

2. Bitmap in VB -> ATL COM object

3. ATL COM object in VB w/DAO runs out of Stack Space

4. Accessing ATL COM object from V.S. 2003 Embedded VB.NET app

5. Passing by reference to an ATL COM component

6. Using ATL COM objects with scripting languages

7. Handling events fired from an ATL COM object in VBScript

8. ATL COM Object

9. RFH (Newbie): Objects with ATL COM-server / VBE-client (EXCEL97)

10. Call VB DLL or COM object from within VB COM object or EXE

11. Arrays from ATL COM object

12. com object will not read registry when com object called from asp (vb works fine)

 

 
Powered by phpBB® Forum Software