We help IT Professionals succeed at work.

Using COM objects in Visual C++

Can someone help with the below:

1. Is different coding required depending on whether or not the COM object is running in-process and out-of-process.

2. Is any specific coding required for using DCOM over and above that required for COM.

3. Are there any VC++ recommended standards for COM & DCOM programming.

4. What special programming is required to handle VB COM events and does this differ depending on where the object is running as described in 1 & 2 above.


Thanks
Comment
Watch Question

1. Nope. You pretty much decide that when you create your VC ATL project and from then on you just add components and methods and build.
2. Nope. In most cases just configuration (surrogates; security; etc.)
3. Dunno what you mean by standard...
4. No difference if the components is written in VB. You'll need to add connection point support to your project and implement the appropriate sink interface (like IYourInterfaceEvents). You can do this via the class wizard menu's (right mouse click).

Author

Commented:
Thanks AssafLavie,

3. I have written a COM object DLL in VB for use by a third party who are developing in VC++. I have changed the COM object DLL to an EXE and their code now fails to work - specifically using the COM object events. They are not using ATL. By standard, I mean recommended and/or proven programming techniques for using COM. i.e. their code works for in-process but not out-of-process.

Are there any Microsoft links?

Thanks.
> I have changed the COM object DLL to an EXE

do you have a proxy library registered - you should be able to use type library marshalling (since your componant is VB

Author

Commented:
Shaun,

Thanks for the help but I'm not sure what you mean. My knowledge of C++ is very very limited. My main concern is not how to fix the problem (I'm sure the third parties can figure this out for themselves) but how it could happen.

Is it that extra prgramming is required to use out-of-process COM objects? Is it because the third party are not following MS recommeneded guidelines for implementing COM with VC++?

Or

If I gave you a VB COM DLL (in-process) to use with your code and then I used DCOMCNFG & DLLHOST.EXE and made the COM DLL out-of-process, should I expect your code to work no problem. Would you need to know if it was to be in-process or out-of-process from the outset (ie for specific coding)?
proxys and typelibraries are not C++ specific but COM specific

when COM is calling out-of-proc it needs to know how to move (marshall) the data around - to do this you can use a proxy/stub DLL however if you stick to oleautomation types (which VB does) the you can use the built in marshaler (oleaut32.dll? - its been a while since I used VB in out-of-proc) however you need a typelibrary to inform the standard marshaller what to do (but I always -maybe wrongly- assumed VB bounds its typelibrary into itself)

> should I expect your code to work no problem.

I'd have thought DCOMCNFG might work this out

> Would you need to know if it was to be in-process or out-of-process from the outset

In my experience NO - not for the actual object (the threading model is more of a concern - but VB only knows the single threaded ones eg Apartment) - I am dissapointed the the C++ guys couldn't tell you the reason from the error codes returned when they tried to instantiate the object

have a look at

http://support.microsoft.com/directory/article.asp?ID=KB;EN-US;Q268550

http://support.microsoft.com/support/kb/articles/Q175/5/10.ASP

http://support.microsoft.com/directory/article.asp?ID=KB;EN-US;Q266717

the problem could be security related but - its a hard one to tell without the error codes

look up marshalling and VB in a good VB/COM book

Commented:
I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. Unless there is objection or further activity,  I will suggest to accept "AssafLavie, ShaunWilde" comment(s) as an answer.

If you think your question was not answered at all, you can post a request in Community support (please include this link) to refund your points.
The link to the Community Support area is: http://www.experts-exchange.com/commspt

BSewills
You have 6 open questions out of 8 that need your attention. Please take some time and accept an answer or provide feedback if the experts that try to help you requested that.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
Force-accepted by
Netminder
CS Moderator

ShaunWilde: points for you at http://experts-exchange.com/jsp/qShow.jsp?ta=cplusprog&qid=20280733

Explore More ContentExplore courses, solutions, and other research materials related to this topic.