Looking for help with non-COM C++ interfaces implementation. I can’t
find any reference on how to implement / use non-COM C++ interfaces in C#.
I have an application that uses COM interfaces from one of the Microsoft
services and have no problems using those. However, there are few
interfaces in this service defined as (C++ (not COM) interface)
regarding Microsoft documentation on this service API, also these
interfaces inherit the methods of the standard COM interface IUnknown
(same source).
Making story short, I can successfully call method that returns IntPtr
to the non-COM interface with reasonable pointer value, even
Marshal.QueryInterface works fine and returns proper pointer. My problem
is how to define C# wrapper for this type of interface, looks like
standard way that COM likes, does not work for me.
[ComVisible(false),
ComImport,
InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
Guid("E561901F-03A5-4afe-86D0-72BAEECE7004")]
public interface IProviderNotifications
{
[PreserveSig()]
uint OnLoad([MarshalAs(UnmanagedType.IUnknown)] object pCallback);
[PreserveSig()]
uint OnUnload(int bForceUnload);
}
I tried “Marshal.GetObjectForIUnknown” on returned IntPtr, it just
throws an exception (No such interface) even without me trying to cast
it to specific type. I also tried “Marshal.PtrToStructure” and define my
wrapper class not as interface but as abstract class (blowup with
exception “Cannot create an abstract class”, reasonable).
I hope someone know anything about this issue, any help, suggestion,
hint greatly appreciated. I really stuck now.
Thanks.
mtv - 31 Jan 2007 20:35 GMT
Try this book: Essential Guide to Managed Extensions for C++. You can use "It
Just Works" (IJW) method to wrap your native C++ code w/ managed __gc class.
BTW, the name IJW is quite dump, but the method is nice.
MS does offer a 3-day training course in this topic. Course 2558, but you've
got to make sure instructor is good since there are not that many people
really know about this whole topic.
Good luck.

Signature
Your 2 cents are worth $milion$. Thanks.
> Looking for help with non-COM C++ interfaces implementation. I can’t
> find any reference on how to implement / use non-COM C++ interfaces in C#.
[quoted text clipped - 35 lines]
>
> Thanks.