views:

35

answers:

1

I'm doing drag/drop out of an activeX control. On drag, I provide a CComQIPtr which has COM methods implemented to pass information to the drop target. On drop, the drop target's process calls my COM methods to get information.

Am I not allowed to use CRT types or pointers to CRT types near that interface boundary? I would love for my IDataObject to have a private std::list and some std::strings, and on the foreign side of the interface be able to call my COM methods which can access those private members.

I think it's OK because I'm not actually passing CRT types across the boundary.

MSDN: Potential Errors Passing CRT Objects Across DLL Boundaries

+2  A: 

You can use anything you like in the implementation of your com object as that always stays in the process (or dll) that creates it.

You need to stick to COM types in your COM interface so that the types can be marshalled between the process where your object is used and the process where your object was created.

You are correct. That article doesn't apply to this situation as you aren't passing anything across the boundary. The COM infrastructure deals with marshalling the COM types across the boundary for you.

Just be sure that you catch all exceptions within your COM methods, you can't allow them to leak out of the function as the COM infrastructure wont know what to do with them.

Personally I tend to have a thin layer of COM code that deals with conversion between COM types and 'normal' types and then calls into the code that does the real work (see here). This layer includes an exception handler that catches everything and converts to appropriate HRESULTs.

Len Holgate
so, the interface is like a door from the foreign process to my process, and once you are in my process (hit my breakpoint in my debugger) i can use any types I want, as long as I only pass COM/primitive types back through the door.
Dustin Getz
Pretty much; I tend to think of it more as a border that you have to cross. You can use your local customs on your side of the border but you have to conform to whatever rules those in charge of the border want you to conform to to be able to cross. I wrote about dll borders and COM and .Net here on my blog a while back: http://www.lenholgate.com/archives/000419.html
Len Holgate