I have some DTE-related work I need to do in my VSIP project that is going
to be much easier to implement from managed code instead of unmanaged C++.
How do I pass the DTE interface pointer from my unmanaged code into a
managed assembly? I implemented a managed C++ dll that exports a function
my unmanaged code calls to pass in the DTE interface pointer as an unmanaged
void*. I haven't been able to figure out how to box the interface pointer
back into a managed DTE object? I tried using
System.Reflection.Pointer.Box(pv, type) to box the pointer, but it gives me
an argument-exception because the type refers to an interface and not a
pointer.
Is there an easier way for managed code to get at the DTE interface? I
tried using GetActiveObject, which works just fine as long as there is only
one instance of VS.NET running. If there are multiple instances running
then it is possible that the wrong DTE interface will be returned. From
what I see in the documentation, the only way to get at the DTE interface
(or any other interface) is to either be derived from IServiceContainer or
have been given an IServiceProvider interface, neither of which is true for
my simple managed dll.
"Ed Dore [MSFT]" - 11 Aug 2004 01:52 GMT
Hi Bill,
Is the managed DLL that contains the export a mixed mode DLL? Generally
speaking, I'd avoid passing the DTE object as a void*. From your unmanaged
code, you probably have an IDispatch* on the DTE object, just pass this as
an IDispatch* or IUnknown*. On the managed side, you can use the
Marshal.GetObjectFromIUnknown to retrieve the managed representation of the
DTE object.
Let me know if that doesn't make sense.
Sincerely,
Ed Dore [MSFT]
This post is 'AS IS' with no warranties, and confers no rights.
Brett Keown [MSFT] - 16 Aug 2004 18:06 GMT
Hi Bill,
Did you have any follow-up questions for Ed in regards to this post?
Brett Keown
Microsoft Support
brettke@online.microsoft.com
This posting is provided "AS IS" with no warranties, and confers no rights.
Allen Denver [MS] - 26 Aug 2004 00:32 GMT
See my blog entry titled Can Addins & managed packages live together?;
Getting to the DTE object model from a package at
http://blogs.msdn.com/allend/archive/2004/03/31/104829.aspx for info on how
to accomplish this in managed code. You don't actually get the native dte
interface pointer, you just query for the DTE as a service.
Good luck,

Signature
Allen Denver (Microsoft)
http://blogs.msdn.com/allend
-- This post is provided 'AS IS' with no warranties and confers no rights.
> I have some DTE-related work I need to do in my VSIP project that is going
> to be much easier to implement from managed code instead of unmanaged C++.
[quoted text clipped - 15 lines]
> have been given an IServiceProvider interface, neither of which is true for
> my simple managed dll.